![](/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.