app.xaml
<Application.Resources>
<local:AppBootstrapper xmlns:local="clr-namespace:Kyms" x:Key="Bootstrapper" />
<local:LocalizedStrings xmlns:local="clr-namespace:Kyms" x:Key="LocalizedStrings"/>
<ResourceDictionary x:Key="CustomDictionary">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
我在Styles / Styles.xaml中的资源
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
<Style x:Key="MyColorButton" TargetType="Button">
.......
</Style>
在ViewModel中(使用caliburn micro MVVM Pattern)如果我调用此代码
App.Current.Resources.MergedDictionaries [0]
App.Current.Resources.MergedDictionaries.Count = 0
但不行,为什么?
答案 0 :(得分:0)
我已经解决了
在我的AppBootstrapper.cs中我插入
private void LoadDictionary()
{
var dictionaries = App.Current.Resources.MergedDictionaries;
dictionaries.Clear();
var themeStyles = new ResourceDictionary { Source = new Uri("/MyAssemblyName;component/Styles/Styles.xaml", UriKind.RelativeOrAbsolute) };
dictionaries.Add(themeStyles);
}
它有效!