I've got a XamDataGrid containing a few fields including these two:
<igDP:Field Name="MinValue" Label="Min." Converter="{StaticResource DivideBy1000Converter}" Column="5">
<igDP:Field.Settings>
<igDP:FieldSettings CellWidth="60"
AllowEdit="True"
CellValuePresenterStyle="{StaticResource minValueCellEnabled}"
EditAsType="{x:Type System:String}"
EditorStyle="{StaticResource DecimalMWhStyle}"
CellClickAction="EnterEditModeIfAllowed" />
</igDP:Field.Settings>
</igDP:Field>
<igDP:Field Name="MaxValue" Label="Max." Converter="{StaticResource DivideBy1000Converter}" Column="6">
<igDP:Field.Settings>
<igDP:FieldSettings CellWidth="60"
AllowEdit="True"
CellValuePresenterStyle="{StaticResource maxValueCellEnabled}"
EditAsType="{x:Type System:String}"
EditorStyle="{StaticResource DecimalMWhStyle}"
CellClickAction="EnterEditModeIfAllowed" />
</igDP:Field.Settings>
</igDP:Field>
Due to changing requirements and a bit of time pressure I need to find a way to dynamically change the fields' converter and EditorStyle depending on some value (boolean flag most likely) being present. I've seen general examples using style selectors, but not how to (if even possible) apply a style selector to elements of a XamDataGrid. My initial thought was to use a style selctor class and add two styles for each case, i.e. one for when the field should use the DivideBy1000Converter + DecimalMWhStyle combo and one for when the field should use an empty converter and a PercentageStyle, but along the way I got stuck and I right now I can't figure out how to best achieve what I want.
Does anyone have a good solution to this?
use behaviors to do this quickly.
just build all the styles and field laouts in XAML code and use them inside a behaviour. just look at below code :
I am generating fieldlayout at run time for my grid. And also using the "DataRecordCellAreaStyle", "CellValuePresenterStyle", "LabelPresenterStyle" at run time. This gives you flexibility to permute different styles/converters very easily and it's quite easy to implement and change.