I want to dynamically change custom theme for the whole application. Themes are presented as resource dictionaries called ExpressionDark.xaml and ExpressionLight.xaml (downloaded from Codeplex). I’m using combo box to select appropriate theme. Theme changing is happening at SelectionChanged event. Here’s the code:
private void themesComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ResourceDictionary resourceDictionary = new ResourceDictionary();
int theme = ((ComboBox)sender).SelectedIndex;
switch (theme)
{
case (int)Themes.Dark:
resourceDictionary = Application.LoadComponent(
new Uri(@"Themes\ExpressionDark.xaml",
UriKind.Relative)) as ResourceDictionary;
break;
case (int)Themes.Light:
resourceDictionary = Application.LoadComponent(
new Uri(@"Themes\ExpressionLight.xaml",
UriKind.Relative)) as ResourceDictionary;
break;
default:
break;
}
Application.Current.Resources = resourceDictionary;
}
This works fine for the current window, but when I run an instance of another application window an XamlParseException occurs.
1 Answer