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

Applying theme to control

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

3 Replies

RA Rachel A Syncfusion Team 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. 

BE Benjamin 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.

MK Muneesh Kumar G Syncfusion Team 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. 

Live Chat Icon For mobile
Up arrow icon