我对这些项目有一个解决方案:
1. Clinica (Type is Windows Application),(MainWindow.xaml
在这里)
2. Ferhad.Wpf.Core(类型为类库),(共有三个文件:Resources.xaml
, OrangeResource.xaml
, BlueResource.xaml
)
Resources.xaml
看起来像这样:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Ferhad.Wpf.Core;component/BlueResource.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
现在,从MainWindow.xaml.cs
我想清除并添加OrangeReource.xaml
到Resources.xaml
.
我该怎么做:到目前为止,我已经尝试过:
string fileName = "pack://application:,,,/Ferhad.Wpf.Core;component/OrangeReSource.xaml";
if (System.IO.File.Exists(fileName))
{
using (FileStream fs = new FileStream(fileName, FileMode.Open))
{
ResourceDictionary dic = (ResourceDictionary)XamlReader.Load(fs);
string fileNameR = "pack://application:,,,/Ferhad.Wpf.Core;component/Resources.xaml";
if (System.IO.File.Exists(fileNameR))
{
using (FileStream fsR = new FileStream(fileNameR, FileMode.Open))
{
ResourceDictionary dicR = (ResourceDictionary)XamlReader.Load(fsR);
dicR.MergedDictionaries.Clear();
dicR.MergedDictionaries.Add(dic);
}
}
}
}
谢谢。