Skip to content

SyncfusionExamples/set-different-background-color-for-each-column-header-in-maui-datagrid

Repository files navigation

Set different Background Color for each column header in MAUI DataGrid

The .NET MAUI DataGrid (SfDataGrid) allows you to set different background color for each column header by using the DataGridColumn.HeaderTemplate property. The below code illustrates how to set the different background color for each column header.

XAML

<syncfusion:SfDataGrid x:Name ="dataGrid"
                    AutoGenerateColumnsMode="None"
                    ItemsSource="{Binding Employees}">

    <syncfusion:SfDataGrid.Columns>
        <syncfusion:DataGridTextColumn  MappingName="EmployeeID">
            <syncfusion:DataGridTextColumn.HeaderTemplate>
                <DataTemplate>
                    <Label Text="Employee ID"
                        FontAttributes="Bold"
                        TextColor="Black" 
                        BackgroundColor="Gray" 
                        VerticalTextAlignment="Center" 
                        HorizontalTextAlignment="Center"/>
                </DataTemplate>
            </syncfusion:DataGridTextColumn.HeaderTemplate>
        </syncfusion:DataGridTextColumn>

        <syncfusion:DataGridTextColumn  MappingName="Name">
            <syncfusion:DataGridTextColumn.HeaderTemplate>
                <DataTemplate>
                    <Label Text="Name" 
                        FontAttributes="Bold" 
                        TextColor="Black" 
                        BackgroundColor="Blue" 
                        VerticalTextAlignment="Center" 
                        HorizontalTextAlignment="Center"  />
                </DataTemplate>
            </syncfusion:DataGridTextColumn.HeaderTemplate>
        </syncfusion:DataGridTextColumn>

        <syncfusion:DataGridTextColumn  MappingName="IDNumber">
            <syncfusion:DataGridTextColumn.HeaderTemplate>
                <DataTemplate>
                    <Label Text="ID Number" 
                        FontAttributes="Bold" 
                        TextColor="Black" 
                        BackgroundColor="Aqua" 
                        VerticalTextAlignment="Center" 
                        HorizontalTextAlignment="Center"/>
                </DataTemplate>
            </syncfusion:DataGridTextColumn.HeaderTemplate>
        </syncfusion:DataGridTextColumn>
        <syncfusion:DataGridTextColumn  MappingName="Title">
            <syncfusion:DataGridTextColumn.HeaderTemplate>
                <DataTemplate>
                    <Label  Text="Title" 
                        FontAttributes="Bold" 
                        TextColor="Black" 
                        BackgroundColor="Maroon" 
                        VerticalTextAlignment="Center" 
                        HorizontalTextAlignment="Center"/>
                </DataTemplate>
            </syncfusion:DataGridTextColumn.HeaderTemplate>
        </syncfusion:DataGridTextColumn>
    </syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>

The following screenshot shows the Column header with different background,

different Background Color for each column header in SfDataGrid

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 bind DataTable collection to 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 forums, Direct-Trac or feedback portal. We are always happy to assist you!

About

set different background color for each column header in maui datagrid

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5

Languages