NetAdvantage WPF 9.2 XamDataGrid
Following KB010107 I can set a style trigger to highlight a row's bg color based on a value in the item's collection *as long* as there are no unbound fields. However, I'm using several unbound fields and the style trigger is never set. If I allow the grid to autogenerate the fields, the trigger works fine.
Question: How can I apply a style trigger when using unbound fields with a XamDataGrid? Preferably using pure XAML.
Sample XAML:
<Window.Resources>
<Style TargetType="{x:Type igDP:DataRecordCellArea}">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self},
Path=Record.DataItem.SomeProperty.IsOnline}" Value="True">
<Setter Property="Background" Value="Green" />
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<igDP:XamDataGrid x:Name="XamDataGrid1"
DataSource="{Binding Path=MyCollection.Items}">
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout Key="MyKey">
<igDP:FieldLayout.FieldSettings>
<igDP:FieldSettings
CellClickAction="SelectRecord"
AutoSizeOptions="DataCells" AllowRecordFiltering="False" />
</igDP:FieldLayout.FieldSettings>
<igDP:FieldLayout.Fields>
<igDP:UnboundField
Name="EmployeeID"
Label="EmployeeID"
BindingPath="EmployeeID" />
Name="IsOnline"
Label="IsOnline"
BindingPath="SomeProperty.IsOnline" DataType="{x:Type sys:Boolean}" />
<igDP:UnboundField Width="auto"
Name="Name"
Label="Name"
BindingPath="Name" BindingMode="TwoWay" />
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings AutoGenerateFields="False"
AllowAddNew="False"
AllowDelete="False"
AutoFitMode="ExtendLastField"
AllowClipboardOperations="Copy" />
</igDP:XamDataGrid.FieldLayoutSettings>
</igDP:XamDataGrid>
WPF only supports 1 local style. When you set the Theme property, you are putting resources for all the DataPresenter elements into its Resources. Since WPF will encounter that before it gets to the Window as it walks up the ancestor chain, it will use the Style from the Theme (i.e. the one in the grid's Resources). You could put that Style into the Resources of the XamDataGrid instead of the Window but you should be aware that WPF will then use that Style and not the one from the theme so anything that might have come from the theme will not be picked up. If you're always using a specific theme then you could set the BasedOn of your Style to the Style for that element in that theme. e.g. BasedOn="{StaticResource igThemes:DataPresenterPrintBasic.DataRecordCellArea}"
After blind luck I found that the style trigger is overridden whenever a theme is applied to a grid. The example I attached has a theme applied to the 2nd grid; when the theme is removed, the style trigger works as expected.
So, the question needs to be updated: How do I apply a style trigger when using an Infragistics theme on a XamDataGrid?
Hi Alex,
Attached is a sample project demonstrating the described behavior not working.
Hello,
I tested this and it is working as expected. I really do not see any reason why it should work with a normal field and will not work with an UnboundField. If you have a sample project, please attach it so that we can look into this.