直接上代码,已便已后自己查况阅,新手也可以看!
1、新建一个资料类和一个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;