如何在DLL中使用资源字典
本文关键字:资源 字典 DLL | 更新日期: 2023-09-27 17:50:55
我有一个带有资源字典的DLL。如果我从WPF应用程序调用这个字典,一切都会正常工作。但是如果我从控制台应用程序调用字典,我将得到一个错误"URI前缀不被识别"
ResourceDictionary res = new ResourceDictionary();
try
{
res.Source = new Uri("ClassLibrary1;component/SomeDict.xaml", UriKind.Relative);
var l = res["SomeKey"];
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
需要配置Uri。这篇文章会有所帮助。
http://www.yac.com.pl/mt.texts.wpf-tests-pack-uri-handling.en.html http://compilewith.net/2009/03/wpf-unit-testing-trouble-with-pack-uris.htmlUriFormatException: Invalid URI: Invalid port specified
我用了这个
if (!UriParser.IsKnownScheme("pack"))
{
Application app = Application.Current;
}