【问题标题】:Prism embedded image棱镜嵌入图像
【发布时间】:2012-10-28 14:41:44
【问题描述】:

我有一个名为xModule模块。我有一个图像,其中标记为embedded resource

在我尝试过的模块初始化内部:

string stFileName = "SmallIcon.png";
string stAssembly = "xModule"; // That's the full name of the assembly
//img.BeginInit();

Uri uri = new Uri(String.Format(@"/{0};component/Images/{1}", stAssembly , stFileName),
                  UriKind.Relative);
ImageSource imgSource = new BitmapImage(uri);

在到达ImageSource imgSource =.. 行的断点期间,ImageSource 似乎找不到图像...

为什么?它有什么问题?

我没有收到任何错误,程序集被引用。我在 Xaml 中做了类似的事情,它奏效了。 也用过:VS11、Unity

【问题讨论】:

    标签: c# wpf resources prism


    【解决方案1】:

    我认为您需要将图像标记为“资源”而不是“嵌入式资源”( WPF )

    另见:What's the difference between a Resource and an Embedded Resource in a C# application?

    【讨论】:

    • 感谢提供信息,但无论如何结果没有区别。我还尝试了 build:Content。没有不同。 Packed URI's give "Cannot locate resource 'images/smallicon.png'" 这个错误,而我上面在监视期间使用的 URI 显示了类似的结果。正如我之前所说的那样,我不会收到任何错误。
    猜你喜欢
    • 1970-01-01
    • 2019-01-29
    • 2022-10-21
    • 1970-01-01
    • 2019-06-12
    • 1970-01-01
    • 1970-01-01
    • 2019-09-22
    • 1970-01-01
    相关资源
    最近更新 更多