We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Applying theme to control

Thread ID:





147666 Sep 19,2019 06:47 AM UTC Sep 20,2019 11:07 AM UTC Xamarin.Forms 3
Tags: SfChart
Asked On September 19, 2019 06:48 AM UTC

Sorry to have to ask this. But is there a sample on how to toggle between Light Theme and Dark theme for the following syncfusion control by click on a single button.
  • sfChart background
  • data point background for line series
  • segmented control background and text for both selected and unselected
  • gradient
  • button color

I saw the sample added in my pc(C:\Users\Public\Documents\Syncfusion\Xamarin\\sample\Forms\SegmentedControl) when I install syncfusion but can't seems to understand how to change the theme

Thanks a lot

Rachel A [Syncfusion]
Replied On September 19, 2019 07:10 AM UTC

Hi Benjamin, 
Greetings from Syncfusion. 
We kindly request you to refer the below documentation link to know detailed information on applying themes for Syncfusion controls. 

Replied On September 19, 2019 07:32 AM UTC

Hi Rachel,

Thanks for replying to my post. i have read the documentation but am still not sure how to implement it. 

from my previous post about gradient view i understand that i need to apply theme for gradient view differently, thus i am also unsure how do i merge these together?

for the data marker color, i have a custom data marker for bar chart which need to do theming and data marker for line series without any custom style.

not sure how do i handle the theme for these 2 separately.

Muneesh Kumar G [Syncfusion]
Replied On September 20, 2019 11:07 AM UTC

Hi Benjamin, 
Thanks for your update.   
We have achieved your requirement by creating custom theme files and specified the values in it based on the keys. Then change the theme file by using the button click dynamically. Please refer the below code. 
Code snippet [XAML]: DarkTheme.xaml 
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms" 
    <Color x:Key="SfChartAxisLineColor">White</Color> 
    <Color x:Key="SfChartMajorTickLineColor">White</Color> 
    <Color x:Key="SfChartAxisLabelColor">White</Color> 
    <Color x:Key="SfChartMajorGridLineColor">White</Color> 
    <Color x:Key="SfChartBackgroundColor">Black</Color> 
    <Color x:Key="backgroundColor">Yellow</Color> 
    <Color x:Key="color1">Red</Color> 
    <Color x:Key="color2">Blue</Color> 
Code snippet[C#]: 
private void Button_Clicked(object sender, EventArgs e) 
    if (isLightTheme) 
        ICollection<ResourceDictionary> mergedDictionaries = this.Resources.MergedDictionaries; 
        var lightTheme = mergedDictionaries.OfType<LightTheme>().FirstOrDefault(); 
        if (lightTheme != null) 
        mergedDictionaries.Add(new DarkTheme()); 
        isLightTheme = false; 
        ICollection<ResourceDictionary> mergedDictionaries = this.Resources.MergedDictionaries; 
        var darkTheme = mergedDictionaries.OfType<DarkTheme>().FirstOrDefault(); 
        if (darkTheme != null) 
        mergedDictionaries.Add(new LightTheme()); 
        isLightTheme = true; 
Code snippet[XAML]: 
                <x:String x:Key="SfChartTheme">CommonTheme</x:String> 
            <StackLayout BackgroundColor="{DynamicResource backgroundColor}" > 
                <Label Text="High" /> 
Please let us know if you have any other queries.  
Muneesh Kumar G. 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon