Jun 24

Hi,

Here is an example of how to change in a WPF application the theme at runtime.

WPF change Theme

As you can see  when we cahnge the selected combobox item it automatically changes the theme, which actually clears the application’s resources and loads adifferent xaml file with resources and added this to the SelectionChanged event.

 private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ResourceDictionary skin = new ResourceDictionary();
skin.Source = new Uri(@”" + cbxThemes.SelectedValue.ToString() + “.xaml”, UriKind.Relative);
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(skin);
}

Here you can download the sample files.

WPF change Theme sample