Search code examples
c#xamluwpteleriktelerik-grid

Changing color of specific Row in Telerik UWP RadDataGrid


I have the following XAML in my view:

<tg:RadDataGrid ColumnDataOperationsMode="Flyout"  x:Name="grid3" ItemsSource="{x:Bind ViewModel.MappingSource}" SelectedItem="{x:Bind ViewModel.CurrentMapping, Mode=TwoWay}" UserEditMode="{x:Bind ViewModel.CanEdit, Mode=TwoWay}"  Grid.ColumnSpan="4" Grid.Row="1" AutoGenerateColumns="False" RowBackground="{x:Bind ViewModel.ValidateModBank}">

Please take a look at the end of the line where it sets the RowBackground property. At this time my ValidateModBank property returns the color red based on certain criteria.

The problem is that all the rows in the RadDataGrid get changed to red, but I only want specific rows to change - based on ValidateModBank.

How can I achieve this?


Solution

  • The RowBackground property is used to sets the Brush that defines the fill of each row, it's not for a specific row.

    According to your description, you might want to change background of the selected row.

    You could use its Implicit Styling.

    Setting the SelectionRegionBackground Control for it.

    <telerikGrid:RadDataGrid.Resources>
        <Style TargetType="gridPrimitives:SelectionRegionBackgroundControl">
            <Setter Property="Background" Value="Red"/>
            <Setter Property="BorderBrush" Value="Green"/>
            <Setter Property="BorderThickness" Value="2"/>
        </Style>
    </telerikGrid:RadDataGrid.Resources>