WPF change theme/style at runtime


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);

Here you can download the sample files.

WPF change Theme sample

2 thoughts on “WPF change theme/style at runtime

  1. DRWebMonkey

    Very cool and simple. I was thinking of using something like to this to allow increased font size as well as the appearance.

    I had to remove the Height Setters to make that work correctly or the button clips the text.

    I would probably have created a directory for the themes, and then read the directory to build the theme list.


Leave a Reply