How to Configure the Syncfusion Theme for .NET MAUI Chart(SfCartesianChart)?
This guide will walk you through configuring and customizing the .NET MAUI Syncfusion® theme for the SfCartesianChart. Syncfusion® themes enable you to apply colors uniformly to .NET MAUI Cartesian Charts, providing a consistent look and feel for your applications.
Let’s take a look at the following sections:
- How to Set the Theme for the Application
- Dynamically Changing Themes
- Overriding the Default Theme
How to Set the Theme for the Application
By default, Syncfusion® provides support for both light and dark themes through the inclusion of a SyncfusionThemeResourceDictionary.
Initialize and assign the desired theme in your application, modify the App.xaml file as follows:
<Application xmlns:syncTheme="clr-namespace:Syncfusion.Maui.Themes;assembly=Syncfusion.Maui.Core">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<syncTheme:SyncfusionThemeResourceDictionary VisualTheme="MaterialLight"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Light Theme
Dark Theme
Dynamically Changing Themes
Syncfusion® allows for dynamic theme switching within your application. This can be achieved by updating the VisualTheme property at runtime. Here is an example in C#:
ICollection<ResourceDictionary> mergedDictionaries = Application.Current.Resources.MergedDictionaries;
if (mergedDictionaries != null)
{
var theme = mergedDictionaries.OfType<SyncfusionThemeResourceDictionary>().FirstOrDefault();
if (theme != null)
{
if (state == false)
{
theme.VisualTheme = SfVisuals.MaterialLight;
}
else
{
theme.VisualTheme = SfVisuals.MaterialDark
}
}
}
Overriding the Default Theme
The theme resource dictionary contains a set of keys that are mapped to styles in control style dictionaries. The default appearance of themes can be customized by overriding these key values. You can find the keys for the Cartesian Chart here: Cartesian Chart Theme Keys.
For example, the major grid lines and tooltip background values are customized by overriding theme keys.
<Application xmlns:syncTheme="clr-namespace:Syncfusion.Maui.Themes;assembly=Syncfusion.Maui.Core">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<syncTheme:SyncfusionThemeResourceDictionary VisualTheme="MaterialLight"/>
<ResourceDictionary>
<Color x:Key="SfCartesianChartMajorGridLineStroke">Lime</Color>
<Color x:Key="SfCartesianChartTooltipBackground">Pink</Color>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
For more information, please refer to the Syncfusion® .NET MAUI Cartesian Chart Theme Demo
Conclusion
I hope you enjoyed learning how to configure and customize themes in your .NET MAUI applications using the Syncfusion®'s SfCartesianChart control.
You can refer to our .NET MAUI Cartesian Chart feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI Chart documentation to understand how to present and manipulate data. For current customers, check out our components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our other controls. 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!