【问题标题】:How to use ResourceDictionary in DLL from ConsoleApp?如何在 ConsoleApp 的 DLL 中使用 ResourceDictionary?
【发布时间】:2015-05-28 08:25:00
【问题描述】:

我有一个带有 ResourceDictionary 的 DLL。 如果我从 WPF 应用程序调用这个字典,一切都会正常工作。 但是,如果我从控制台应用程序调用 dict,我会收到错误“无法识别 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);
        }

【问题讨论】:

  • 尝试指定full Uri(或如何调用):click
  • @Sinatr 现在我有这个错误 Invalid URI: invalid port。我用这个: res.Source = new Uri("pack://application:,,,/ClassLibrary1;component/SomeDict.xaml");我尝试将 ResourceDictionary 添加到 ConsoleApp 中。当我调用它时,我得到了同样的错误。

标签: c# wpf uri resourcedictionary


【解决方案1】:

需要配置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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多