Reputation: 817
I want to to bind the entire row's background with a boolean property for each record in XAML.
There are too many ways to change datagrid's style but I want to change the specific style that is responsible for the entire row...
For example, the class Record is the bound data behind the datagrid and it has a boolean property "Correct" (true / false), I'd like the datagrid to show the row with false Correct in red background, green when true.
I tried to use CellStyle but it only changes the background in each cell in the row, not the whole row.
Upvotes: 0
Views: 1323
Reputation: 42991
As mentioned use DataGrid.RowStyle, for example:
<Style x:Key="DataGridRowCorrectStyle" TargetType="{x:Type Toolkit:DataGridRow}">
<Setter Property="Background" Value="Green"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Correct}" Value="False">
<Setter Property="Background" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
<Toolkit:DataGrid RowStyle={StaticResource DataGridRowCorrectStyle} ... />
Upvotes: 2
Reputation: 3803
To change the background color of a row you'll need to change the background color of each cell in the row. Create a Style which sets the Background color and then assign it to the CellStyle member. If you want to set the color with the RowStyle set the background color of the cells to Transparent and then set the color with the RowStyle style.
Upvotes: 0