How to change the theme in .NET MAUI DataGrid?
The Syncfusion® themes provide a consistent look and feel across all Syncfusion® controls by applying colors uniformly. You can customize the theme of the .NET MAUI DataGrid by following these 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 demonstrate the theming of the DataGrid.
Material Dark
Material Light
Download the complete sample from GitHub.
Conclusion
I hope you enjoyed learning about how to change the theme in .NET MAUI DataGrid.
You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data.
For current customers, check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI DataGrid and other .NET MAUI components.
Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!