WPF中的图像作为嵌入资源 [英] Images in WPF as embedded resources
本文介绍了WPF中的图像作为嵌入资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为images的文件夹,其中包含我的WPF应用程序所需的图像。
现在我想将它们用作XAML和Runtime的资源。
是否有可能,如果是的话(MVVM方式)?
谢谢:)
I have folder called images which contains images needed for my WPF app.
Now I want to use them as resource from XAML and from Runtime.
Is it possible, if yes how (MVVM way) ?
Thanks :)
推荐答案
您只需要将图像的构建操作设置为属性中的资源,然后你可以正常地引用它们
a。代码
You just need to set your image's build action to Resource in properties, then you can refer to them as normal
a. in code
public Image MyIcon
{
get
{
return new Bitmap(@"images\yourImage.bmp");
}
}
b。在XAML
b. in XAML
Icon="Images\yourIcon.ico"
这篇关于WPF中的图像作为嵌入资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文