在我的app.xaml中我有很多样式加载这个列表
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/dark.xaml"/>
<ResourceDictionary Source="Themes/Orange.xaml"/>
<ResourceDictionary Source="Controls/Button.xaml"/>
<ResourceDictionary Source="Controls/CheckBox.xaml"/>
<ResourceDictionary Source="Controls/Controls.xaml"/>
<ResourceDictionary Source="Controls/ContextMenu.xaml"/>
<ResourceDictionary Source="Controls/ScrollBar.xaml"/>
<ResourceDictionary Source="Controls/ScrollViewer.xaml"/>
......
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
现在我需要在运行时更改两个源URL,也可以从Properties.Settings.Default中更改值 我不知道我能做什么 我搜索这个,但没有什么不能找到理解
答案 0 :(得分:0)
var newsource1= new Uri("pack://siteoforigin:,,,/resources/xxxx.xaml", UriKind.RelativeOrAbsolute);
var newsource2= new Uri("pack://siteoforigin:,,,/resources/yyyyy.xaml", UriKind.RelativeOrAbsolute);
Application.Current.Resources.MergedDictionaries.Remove(Application.Current.Resources.MergedDictionaries[0]);
Application.Current.Resources.MergedDictionaries.Remove(Application.Current.Resources.MergedDictionaries[1]);
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = newsource1});
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = newsource2});
由于没有可用于编辑资源字典运行时的功能。实现您期望的可能解决方案是删除和添加资源字典运行时。
此致
Thiyagu Rajendran
**如果有帮助,请将回复标记为答案。