【发布时间】:2012-02-15 19:48:26
【问题描述】:
我想动态更改整个应用程序的自定义主题。主题以资源字典的形式呈现,称为 ExpressionDark.xaml 和 ExpressionLight.xaml(从 Codeplex 下载)。我正在使用组合框来选择合适的主题。主题更改发生在 SelectionChanged 事件中。代码如下:
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;
}
这适用于当前窗口,但是当我运行另一个应用程序窗口的实例时,会发生 XamlParseException。
【问题讨论】:
标签: wpf dynamic themes resourcedictionary