New to Telerik UI for WPF? Download free 30-day trial

How to Change Theme Variation During Runtime

Environment

Product Version 2020.3.1020
Product Progress® Telerik® UI for WPF

Description

How to change a theme's variation during runtime.

Solution

To change a theme's variation during runtime and reflect this change in the UI, you need to call the LoadPreset method and reload the required resource dictionaries.

private void ThemeVariationsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) 
{ 
    var selectedItem = (RadComboBoxItem)e.AddedItems[0]; 
    var colorVariationName = selectedItem.Content.ToString(); // Light or Dark 
    var colorVariation = (FluentPalette.ColorVariation)Enum.Parse(typeof(FluentPalette.ColorVariation), colorVariationName); 
    FluentPalette.LoadPreset(colorVariation); 
    OnResetTheme(); 
} 
 
private static void OnResetTheme() 
{ 
    Application.Current.Resources.MergedDictionaries.Clear(); 
    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() 
    { 
        Source = new Uri("/Telerik.Windows.Themes.Fluent;component/Themes/System.Windows.xaml", UriKind.RelativeOrAbsolute) 
    }); 
    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() 
    { 
        Source = new Uri("/Telerik.Windows.Themes.Fluent;component/Themes/Telerik.Windows.Controls.xaml", UriKind.RelativeOrAbsolute) 
    }); 
    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() 
    { 
        Source = new Uri("/Telerik.Windows.Themes.Fluent;component/Themes/Telerik.Windows.Controls.Input.xaml", UriKind.RelativeOrAbsolute) 
    }); 
 
    // add any other required dictionaries 
} 

See Also

In this article
Not finding the help you need? Improve this article