C# 在code-WPF中选择多个资源字典之一
我已经为组合在一起的控件开发了几个具有不同样式的WPF资源字典 在我的新项目中,我无法决定我最喜欢哪一个,所以我想设置一个设置,让用户能够在它们之间切换 目前我在App.xaml文件中定义资源字典如下:C# 在code-WPF中选择多个资源字典之一,c#,wpf,resourcedictionary,C#,Wpf,Resourcedictionary,我已经为组合在一起的控件开发了几个具有不同样式的WPF资源字典 在我的新项目中,我无法决定我最喜欢哪一个,所以我想设置一个设置,让用户能够在它们之间切换 目前我在App.xaml文件中定义资源字典如下: <Application.Resources> <ResourceDictionary Source="/Styles/BlueStyle.xaml" /> </Application.Resources> 是否可以在C#代码中定
<Application.Resources>
<ResourceDictionary Source="/Styles/BlueStyle.xaml" />
</Application.Resources>
是否可以在C#代码中定义它,这样我就可以从样式列表(可能是从下拉框中)中进行选择,而不是锁定在一个样式列表中
提前感谢将在运行时设置资源:
Application.Current.Resources.Source = new Uri("/Styles/BlueStyle.xaml", UriKind.RelativeOrAbsolute);
或者在组合框中选择更改(其中包含BlueStyle
和RedStyle
等项):
ResourceDictionary dictionary = new ResourceDictionary();
dictionary.Source = new Uri(@"/Styles/" + comboBox.SelectedValue.ToString() + ".xaml", UriKind.Relative);
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(dictionary);