[WPF]资源字典——程序集之间的资源共享 简单换皮肤

时间:2021-09-20 11:28:14

直接上代码,已便已后自己查况阅,新手也可以看!

1、新建一个资料类和一个WPF工程

[WPF]资源字典——程序集之间的资源共享 简单换皮肤

2、APP.XAML应该资源字典,注意应Source格式,前面一定要有“/”

<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ResourceDic;component/Dictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

3、换资源字典按钮代码

ResourceDictionary newDic=new ResourceDictionary();
newDic.Source = new Uri("/ResourceDic;component/Dictionary2.xaml", UriKind.Relative);
Application.Current.Resources.MergedDictionaries[] = newDic;