Articles in this section
Category / Section

How to change the theme in .NET MAUI DataGrid?

3 mins read

Syncfusion themes allow you to apply colors across all the Syncfusion controls with a uniform approach and provide a consistent look and feel to your applications. We can customize the theme of the .NET MAUI DataGrid by the following steps.

By default, DataGrid offers support for both light and dark themes through the inclusion of a SyncfusionThemeResourceDictionary.

XAML

To apply themes to your application, merge the SyncfusionThemeResourceDictionary item.

<Application xmlns:base="clr-namespace:GettingStarted"
             xmlns:syncTheme="clr-namespace:Syncfusion.Maui.Themes;assembly=Syncfusion.Maui.Core"
             x:Class="GettingStarted.App"
             ...>
    <Application.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <!-- Theme resource dictionary -->
                    <syncTheme:SyncfusionThemeResourceDictionary SfVisualTheme="MaterialDark"/>
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
    </Application.Resources>
</Application>

How to toggle between light theme and dark theme

Refer to the following example code to switch between light and dark themes in DataGrid.

C#
void UpdateTheme(object sender, System.EventArgs e)
{
    ICollection<ResourceDictionary> mergedDictionaries = Application.Current.Resources.MergedDictionaries;
    if (mergedDictionaries != null)
    {
        var theme = mergedDictionaries.OfType<SyncfusionThemeResourceDictionary>().FirstOrDefault();
        if (theme != null)
        {
            if (theme.SfVisualTheme is SfVisuals.MaterialDark)
            {
                theme.SfVisualTheme = SfVisuals.MaterialLight;
            }
            else
            {
                theme.SfVisualTheme = SfVisuals.MaterialDark;
            }
        }
    }
}

The following images demonstrates the theming of datagrid.

Material Dark

SfDataGrid_DarkTheme.png

Material Light

SfDataGrid_LightTheme.png

View sample in 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 change the theme in .NET MAUI DataGrid?

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!

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