Hello
I would like to change the background of a entire row based on the value of a property (string). I thought about using a converter,
but I'm unsure on how to achieve this.
Should it change anything, the datagrid is bound to hierarchical data and this requirement applies to the subgrid.
Thanks in advance!
Hello,
Thank you for your reply. I was looking into your scenario and you can apply the DataRecordCellArea style only for the second field layout as you define it with a Key and assign it only on the second field layout like e.g. :
<igDP:XamDataGrid x:Name="XamDataGrid1">
<igDP:XamDataGrid.Resources>
<local:MyConverter x:Key="con"/>
<Style x:Key="drcaStyle" TargetType="igDP:DataRecordCellArea">
<Setter Property="Background" Value="{Binding Path=Record.DataItem, RelativeSource={RelativeSource Self}, Converter={StaticResource con}}"/>
</Style>
</igDP:XamDataGrid.Resources>
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings AutoGenerateFields="False" HighlightAlternateRecords="True"/>
</igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout Key="Category" >
<igDP:FieldLayout.Fields>
<igDP:Field Name="Name"
Label="Name" />
<igDP:Field Name="Books"/>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
<igDP:FieldLayout Key="Book">
<igDP:FieldLayout.Settings>
<igDP:FieldLayoutSettings HighlightAlternateRecords="False" DataRecordCellAreaStyle="{StaticResource drcaStyle}"/>
</igDP:FieldLayout.Settings>
<igDP:Field Name="Isbn"
Label="Isbn" />
<igDP:Field Name="Title"
Label="Title" />
<igDP:Field Name="Author"
Label="Author" />
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
I am attaching a modified version of my sample application(DataGridHierarchy2.zip) that shows this approach.
Please let me know, if you need any further assistance on this matter.
That works! However i have one more problem.
Our main grid (that is the grid that contains the level 0 hierarchical data) uses alternating colors for the rows.
I'd like this to remain this way, and that only the data on level 1 (in the sub grid) is effected by this new style.
An alternative might be to detect in the converter whether it's the main or subgrid? In our application this is possible based on the type of the row, but i'm not sure how to detect whether it's an alternating row?
Kind regards!
I have been looking into your requirement and my suggestion is to create a style for the DataRecordCellArea and bind its Background property to the DataItem of the corresponding record. For the setting of the desired brush you need to use value converter like e.g :
<Style TargetType="igWPF:DataRecordCellArea">
I am attaching a sample application that shows this approach(DataGridHierarchyConverter.zip).