![](/img/trans.png)
[英]WPF ResourceDictionary converter resource not found when startup project is a class library
[英]Change Resource file at runtime in different class library project in same solution in WPF
我与这些项目的解决方案:
1. Clinica (类型为Windows应用程序),( 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);
}
}
}
}
谢谢。
我已经完成了这样的工作:
var rDictionary = new ResourceDictionary();
rDictionary.Source = new Uri(string.Format("pack://application:,,,/Ferhad.Wpf.SystemStyles;component/OStyles.xaml"), UriKind.Absolute);
this.Resources.MergedDictionaries.Add(rDictionary);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.