包括用于棱镜模块的图标 [英] Include an icon for a Prism module

查看:253
本文介绍了包括用于棱镜模块的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的棱镜的外壳可以显示每个它发现模块中的图像和标签。我怎么可能会去,包括图像从一个模块组装和访问它的壳呢?

I want my Prism shell to display an image and label for each module that it discovers. How might I go about including an image from a module assembly and accessing it in the shell?

我已经尝试过提供一个图标创建一个接口(作为的ImageSource )和一个字符串的标签,但我有创造的的ImageSource 从模块的组装的形象。 (该URI用于构造一个的BitmapImage 总想找到shell的组件,而不是模块的组件内容。)

I've already tried creating an interface for providing an icon (as an ImageSource) and a string label, but I am having trouble creating the ImageSource from the image in the module's assembly. (The URI used in the constructor for a BitmapImage always wants to find content in the shell's assembly rather than the module's assembly.)

我在想,我可以添加图像作为一种资源,只使用,但它重新psented在code为$ P $ System.Drawing.Bitmap ,我无法找到一个明显的方法将其转换成一个类型在WPF的外壳使用。 (我没有看到<一href="http://stackoverflow.com/questions/94456/load-a-wpf-bitmapimage-from-a-system-drawing-bitmap">some code 从一个位图,但感觉就像是错误的做法可能不得不接受这一说法,虽然)

I was thinking that I could add an image as a resource and just use that, but it is represented in code as a System.Drawing.Bitmap and I couldn't find an obvious way to convert that to a type usable in the WPF shell. (I did see some code for converting from a Bitmap, but that feels like the wrong approach. Might have to settle with that, though.)

推荐答案

帕特,你的问题很可能是因为你没有使用正确的路径图像。你要加载的视图中的构造函数或东西,图像,然后它没有找到导入失败。 你想仔细检查你的形象是否被编译为资源。 使用这个(假设你的图像被称为的icon.png并locatd在模块项目的根目录)

Pat, your problem is most likely because you do not use the correct path to the image. You are trying to load that image in the view constructor or something then it does not find the import fails. You wanna double check whether your image is compiled as Resource. Use this (assuming your image is called Icon.png and is locatd in the root of your module project)

public BitmapImage Icon
{
    get
    {
        var assembly = Assembly.GetCallingAssembly();

        Uri uri = new Uri("/" + GetType().Assembly.ToString().Split(',')[0] + ";component/Icon.png", UriKind.Relative);

        if (_icon == null)
            _icon = new BitmapImage(uri);

        return _icon;
    }
}

这篇关于包括用于棱镜模块的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆