Articles in this section
Category / Section

How to apply alternate row background for UnBoundRows in SfDataGrid?

1 min read

You can apply the alternate row background for UnBoundRows, by writing style of TargetType as GridUnBoundRowCell and change the background using converter based on row index.

 

XAML

<Window.Resources>
    <local:UnBoundRowStyleConverter x:Key="UnBoundRowStyleConverter" />
        <Style TargetType="Syncfusion:GridUnBoundRowCell">
            <Setter Property="Background" Value="{Binding Converter={StaticResource UnBoundRowStyleConverter}, RelativeSource={RelativeSource Self}}" />
        </Style>
</Window.Resources>

C#

public class UnBoundRowStyleConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        var index = (value as GridUnBoundRowCell).ColumnBase.RowIndex;
        if (index % 2 == 0)
            return Colors.Bisque.ToString();
        else
            return Colors.LightSkyBlue.ToString();
    }
 
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return null;
    }
}

 

Employee table


Sample Links:

WPF

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied