简体   繁体   English

Blend(XAML)不支持Image.Source中的png图像

[英]My png image in Image.Source is not supported by Blend (XAML)

I try to show an Image in my WPF application and added the following code: 我尝试在WPF应用程序中显示Image ,并添加以下代码:

<Image Height="20" Width="20" DockPanel.Dock="Left" Source="pack://application:/Testapp.Model/Resources/Icons/systemEnviromentActor.png"/>

However I get the error that blend does not support this type of Image. 但是,我得到一个错误,即Blend不支持这种类型的图像。 Microsofts page says that Image does support .png . 微软的网页说Image确实支持.png

I created the Image with Paint.net 我用Paint.net创建了图像

The URI is invalid. URI无效。 A valid Resource File Pack URI would look like shown below, where Testapp.Model is an assembly name. 有效的资源文件包URI如下所示,其中Testapp.Model是程序集名称。

pack://application:,,,/Testapp.Model;component/Resources/Icons/systemEnviromentActor.png

If the image file is in the same assembly, you could write it as 如果映像文件在同一程序集中,则可以将其写为

pack://application:,,,/Resources/Icons/systemEnviromentActor.png

In XAML, you could then even omit the prefix, and just write 在XAML中,您甚至可以省略前缀,然后编写

Source="/Resources/Icons/systemEnviromentActor.png"

Also make sure that the Build Action of the image file is set to Resource . 还要确保将图像文件的“生成操作”设置为“ Resource

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM