Mathak Mathak - 2 months ago 3x
C# Question

Change background for specific rows in datagrid wpf

I have a datagrid "Funds" bind to a listcollectionview.

I want to highlight specific rows in datagrid based on few rules. The fundGroupsList is the list of group names. The rule1 is to find the misalignment within members of a group.


One of the ways to do that is to create a boolean property (ex. IsRule1Failed) in Entries and save the fail result foreach row.

Then, in XAML use DataTriggers to change the background color.

      <Style TargetType="DataGridCell">
             <Trigger Property="IsSelected" Value="True">
                 <Setter Property="Background" Value="BurlyWood" />
             <DataTrigger Binding="{Binding DataContext.IsRule1Failed}" Value="True">
                 <Setter Property="Background" Value="Red"></Setter>