Posted 17 April 2020, 2:41 am EST
Hi,
In order to achieve this, you can create a style for DataGridRowPresenter as follows:
<local:Converter x:Key="BackgroundConverter"></local:Converter>
<Style x:Key="RowStyle" TargetType="c1:DataGridRowPresenter">
<Setter Property="Background" Value="{Binding Path=Row.DataItem, RelativeSource={RelativeSource Self}, Converter={StaticResource BackgroundConverter}}"></Setter>
</Style>
c1:C1DataGrid x:Name="dataGrid" RowStyle="{StaticResource RowStyle}"></c1:C1DataGrid>
Where converter will be as follows:
public class Converter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
if ((value as DataModel).Category == "Old")
{
return Brushes.Green;
}
else
{
return null;
}
}
return null;
}
...
}
Returning ‘null’ will let the DataGrid to provide background (alternative) for rows we didn’t want to have any specific background color.
Also, another approach could be to handle the LoadedRowPresenter & UnloadedRowPresenter event to change Row Background.
Please refer the same from the sample attached below.
Regards,
Basant
DataGridRowBackgound.zip