如何在 XAML 中引用图像资源? [英] How to reference image resources in XAML?

查看:37
本文介绍了如何在 XAML 中引用图像资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个窗口上放置了一个 Image 控件,我想显示一个存储在名为Resources.resx"的项目资源文件中的图像.资源文件中图像的名称是搜索".

I put an Image control on a Window and I would like to display an image that is stored in a project resource file named "Resources.resx". The name of the image in the resource file is 'Search'.

有人可以告诉我如何去做吗?

Could someone show me how I might go about doing this?

推荐答案

如果图像在您的资源文件夹中并且其构建操作设置为 Resource.您可以按如下方式在 XAML 中引用图像:

If the image is in your resources folder and its build action is set to Resource. You can reference the image in XAML as follows:

"pack://application:,,,/Resources/Search.png"

假设您在 Resources 文件夹下没有任何文件夹结构并且它是一个应用程序.例如我使用:

Assuming you do not have any folder structure under the Resources folder and it is an application. For example I use:

ImageSource="pack://application:,,,/Resources/RibbonImages/CloseButton.png"

当我在 Resources 文件夹下有一个名为 RibbonImages 的文件夹时.

when I have a folder named RibbonImages under Resources folder.

这篇关于如何在 XAML 中引用图像资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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