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\17.2.0.34\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. 
 
Thanks, 
Rachel. 



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" 
                                      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
                                      x:Class="Chart_GettingStarted.DarkTheme"> 
  
    <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> 
  
</ResourceDictionary> 
  
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.Remove(lightTheme); 
        } 
         
        mergedDictionaries.Add(new DarkTheme()); 
  
        isLightTheme = false; 
    } 
    else 
    { 
        ICollection<ResourceDictionary> mergedDictionaries = this.Resources.MergedDictionaries; 
        var darkTheme = mergedDictionaries.OfType<DarkTheme>().FirstOrDefault(); 
        if (darkTheme != null) 
        { 
            mergedDictionaries.Remove(darkTheme); 
        } 
  
        mergedDictionaries.Add(new LightTheme()); 
         
        isLightTheme = true; 
    } 
} 
  
Code snippet[XAML]: 
<ContentPage.Resources> 
    <syncTheme:SyncfusionThemeDictionary> 
        <syncTheme:SyncfusionThemeDictionary.MergedDictionaries> 
            <ResourceDictionary> 
                <x:String x:Key="SfChartTheme">CommonTheme</x:String> 
            </ResourceDictionary> 
        </syncTheme:SyncfusionThemeDictionary.MergedDictionaries> 
    </syncTheme:SyncfusionThemeDictionary> 
</ContentPage.Resources> 
  
<chart:ChartDataMarker> 
    <chart:ChartDataMarker.LabelTemplate> 
        <DataTemplate> 
            <StackLayout BackgroundColor="{DynamicResource backgroundColor}" > 
                <Label Text="High" /> 
            </StackLayout> 
        </DataTemplate> 
    </chart:ChartDataMarker.LabelTemplate> 
</chart:ChartDataMarker> 
  
  
  
Please let us know if you have any other queries.  
 
Thanks, 
Muneesh Kumar G. 


Loader.
Live Chat Icon For mobile
Up arrow icon