Hi guys, I've read the examples on the forum that show how to define a style (specifically targeted to a XamNumericEditor), that sets the background color based on its "Value" that gets set from a property on an item in an XamDataGrid.
So, if I have a list of items that a grid is bound to, and each of those items has a non-browsable "Precision" property (that won't be displayed by the grid) then my question is this...
How would I set the Mask property on an XamNumericEditor to alter the precision (per cell), NOT based on the Value in the editor, but on a Precision property belonging to the items bound into the grid? e.g a string that I would use to map to a specific precision.
I tried doing something like this, where the intent was to access the parents binding context in the hope that I could access the current items Precision property and then pass that to a PrecisionConverter that would return the correct mask...
<Style TargetType="{x:Type igEditors:XamNumericEditor}">
<Setter Property="Background" Value="{Binding Path=Value, RelativeSource={RelativeSource Self}, Converter={StaticResource itemColorBackgroundConverter} }" />
<Setter Property="Mask" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=igDP:XamDataGrid}, Path=/Precision, Converter={StaticResource itemPrecisionConverter}}" />
</Style>
Thanks...
I found that using WPF Snoop helped hugely. I've been able to view the visual tree of my application and the settings of the properties and values on controls like XamNumericEditor, and found that all you need to do is use the DataContext property.
Define a style targeted at the XamNumericEditor type and add triggers
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=DataContext.DataItem.SomePropertyOnTheBoundItem.SomeOtherPropertyOfThatETC}" Value="False">
<Setter Property="Background" Value="AliceBlue" />
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=DataContext.DataItem.SomePropertyOnTheBoundItem.SomeOtherPropertyOfThatETC}" Value="True">
<Setter Property="Background" Value="LemonChiffon" />
</Style.Triggers>
The important part of this is using the DataContext.DataItem in your binding, so you're not just tied to using triggers, you can apply this technique using converters too.