ResourceDictionary中的WPF图像 [英] WPF image in ResourceDictionary

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

问题描述

嗨我有一个问题应该很容易解决,但显然不适合像我这样的前winform开发人员;-)



所以,有没有人使用合并的ResourceDictionary中引用的图像有一个工作样本?

图像必须嵌入到我的dll /应用程序中。



我尝试过几乎所有的解决方案都可以在互联网上找到,但没有任何运气。



在我的resourceDictionary中我有(以及其他)以下条目:

Hi I have a problem which should be so easy to solve, but apparently it isn't for a former winform developer like me ;-)

So, does anyone have a working sample using Images referenced in a merged ResourceDictionary?
Images must be embedded into my dll/application.

I tried almost all "solutions" found on the internet, but without any luck.

In my resourceDictionary I have(among others) the following entry:

<BitmapImage x:Key="ImageMedal" UriSource="/MyDll;component/Properties/Images/award_star_gold_1.png" />



Nb。我尝试将Image构建为资源和嵌入式资源,但它不会改变任何东西。



我的xaml声明如下:


Nb. I tried building the Image as both Resource and embedded resource, but it doesn't change anything.

My xaml declaration is as the follows:

...
<!--This  works, and shows the Image correctly: -->
<Image Source="/MyDll;component/Properties/Images/award_star_gold_1.png"></Image>

<!--This does NOT work (no error, but the image is just empty) -->
<Image Source="{DynamicResource ImageMedal}"></Image>
...



它确实在设计器中正确显示了两个图像,但在部署时只显示了其中一个。



Nb 。我没有将Image文件导出到deploy目录;而且我不想。



字典正确加载,因为我合并的词典中的很多其他东西都能正常工作。



我做错了什么?


It does show both images correctly in the designer, but only one of them when deployed.

Nb. I did not export the Image file to the deploy directory; and I don't want to.

The Dictionary is loaded correctly since a lot of other stuff from my merged dictionay works fine.

What am I doing wrong?

推荐答案

<bitmapimage x:key="MyDocImage" createoptions="IgnoreImageCache" cacheoption="OnLoad" urisource="pack://application:,,,/DC.Pdb.Plugin.Plugin;component/Properties<br />
/Images/document_editing.png" xmlns:x="#unknown" />


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

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