可以合并主题的App.xaml像这样:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="defaulttheme.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
的defaulttheme.xaml文件必须在你的项目的根。如果你想建立自己的主题日项目可以合并资源这样的:
<ResourceDictionary Source="/MyThemeProject;component/defaulttheme.xaml" />
这里defaulthteme.xaml也必须在MyThemeProject根,不要忘记加上从该项目中添加引用你的主要项目。
要构建一个结构,您可以根据需要添加文件夹。
<ResourceDictionary Source="/MyThemeProject;component/Folder1/Folder2/defaulttheme.xaml" />
要切换主题,先清除MergedDictionaries然后添加新的主题
NewTheme = new Uri(@"/MyThemeProject;component/folder1/Folder2/bluetheme.xaml", UriKind.Relative);
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(NewTheme);
问候
flusser