Articles in this section
Category / Section

How to apply RowStyle in MAUI DataGrid (SfDataGrid)?

2 mins read

The .NET MAUI DataGrid (SfDataGrid) allows you to apply style for the DataGridCells by using the DataGridColumn.CellStyle property. To apply RowStyle for a particular row/rows, you need to apply the same CellStyle for all the DataGridColumns in the row.

XAML

<syncfusion:SfDataGrid x:Name="dataGrid"
                           AutoGenerateColumnsMode="None"
                           ColumnWidthMode="Auto"
                     ItemsSource="{Binding Info}">
 
        <syncfusion:SfDataGrid.Columns>
            <syncfusion:DataGridTextColumn MappingName="ID">
                <syncfusion:DataGridTextColumn.CellStyle>
                    <Style TargetType="syncfusion:DataGridCell">                        
                        <Setter Property="Background" 
                    Value="{Binding ID, Converter={StaticResource colorConverter}}" />
                    </Style>
                </syncfusion:DataGridTextColumn.CellStyle>
            </syncfusion:DataGridTextColumn>
 
            <syncfusion:DataGridTextColumn MappingName="Name">
                <syncfusion:DataGridTextColumn.CellStyle>
                    <Style TargetType="syncfusion:DataGridCell">
                        <Setter Property="Background" 
                    Value="{Binding ID, Converter={StaticResource colorConverter}}" />
                    </Style>
                </syncfusion:DataGridTextColumn.CellStyle>
            </syncfusion:DataGridTextColumn>
 
            <syncfusion:DataGridTextColumn MappingName="Percentage">
                <syncfusion:DataGridTextColumn.CellStyle>
                    <Style TargetType="syncfusion:DataGridCell">
                        <Setter Property="Background" 
                    Value="{Binding ID, Converter={StaticResource colorConverter}}" />
                    </Style>
                </syncfusion:DataGridTextColumn.CellStyle>
            </syncfusion:DataGridTextColumn>
 
            <syncfusion:DataGridTextColumn MappingName="Result">
                <syncfusion:DataGridTextColumn.CellStyle>
                    <Style TargetType="syncfusion:DataGridCell">
                        <Setter Property="Background" 
                    Value="{Binding ID, Converter={StaticResource colorConverter}}" />
                    </Style>
                </syncfusion:DataGridTextColumn.CellStyle>
            </syncfusion:DataGridTextColumn>
        </syncfusion:SfDataGrid.Columns>
    </syncfusion:SfDataGrid>
 

C#

 public class Converter : IValueConverter
{
    object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo info)
    {
        int _value = (int)value;
        if (_value % 2 == 0)
            return Colors.Yellow;
        return Colors.Transparent;
    }
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

 

how to apply row style in maui datagrid

View Sample on GitHub

Take a moment to pursue this documentation, where you can find more about Syncfusion .NET MAUI DataGrid (SfDataGrid) with code examples.

Please refer to this link to learn about the essential features of Syncfusion .NET MAUI DataGrid (SfDataGrid).

Conclusion

I hope you enjoyed learning about how to apply RowStyle in MAUI DataGrid (SfDataGrid).

You can refer to our .NET MAUI DataGrid’s feature tour page to know about its other groundbreaking feature representations. You can also explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data.

For current customers, you can check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our .NET MAUI DataGrid and other .NET MAUI components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac or feedback portal. We are always happy to assist you!

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