如何在 ConsoleApp 的 DLL 中使用 ResourceDictionary?

How to use ResourceDictionary in DLL from ConsoleApp?

我有一个带有 ResourceDictionary 的 DLL。 如果我从 WPF 应用程序调用这个字典,一切都会正常工作。 但是如果我从控制台应用程序调用字典,我会得到一个错误 "The URI prefix s not recognized"

        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.html

UriFormatException : Invalid URI: Invalid port specified

我用过这个

if (!UriParser.IsKnownScheme("pack"))
{
    Application app = Application.Current;
}