WPF自定义控件库中的图像 [英] Images in a WPF Custom Control Library

查看:84
本文介绍了WPF自定义控件库中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将图像放在自定义控件的默认视图中。但是,每当我尝试测试控件时,都无法找到图像。我试图将其编译为嵌入式资源,而在VS中只是普通资源。这些都不起作用。

I need to put an image in the default view of a custom control. However, whenever I try to test the control it can't locate the image. I have tried to compile it as an embedded resource and just a plain resource in VS. Neither of these have worked. So is there a correct way to do this?

推荐答案

那可能是因为您将图像路径指定为相对路径。您应该使用打包URI方案来指定资源位于当前的程序集。例如:

That's probably because you specified the image path as a relative path. You should use the Pack URI Scheme to specify that the resource is in the current assembly. For instance :

<Image Source="pack://application:,,,/Images/MyImage.png"/>

这篇关于WPF自定义控件库中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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