WPF 图像在运行时未呈现
本文关键字:运行时 图像 WPF | 更新日期: 2023-09-27 18:30:31
我有一组从我的解决方案资源文件加载的图像,现在它们在设计模式和 Blend 中显示正常,但当我实际运行程序时它们根本不会显示。
这是控件的标记
<WrapPanel x:Name="heartsWrapPanel" Height="25.97" Canvas.Left="437.94" Canvas.Top="594.83" Width="75.26">
<Image x:Name="heart1" Height="22.388" Width="24.777" HorizontalAlignment="Left" VerticalAlignment="Bottom" Source="pack://siteoforigin:,,,/Resources/heart.png"/>
<Image x:Name="heart2" Height="22.388" Width="24.777" HorizontalAlignment="Left" VerticalAlignment="Bottom" Source="pack://siteoforigin:,,,/Resources/heart.png"/>
<Image x:Name="heart3" Height="22.388" Width="24.777" HorizontalAlignment="Left" VerticalAlignment="Bottom" Source="pack://siteoforigin:,,,/Resources/heart.png"/>
</WrapPanel>
现在我无法弄清楚出了什么问题,包装面板没有任何问题,因为我试图在其中放入其他元素并且它们显示正常,就像我说的那样,图像显示在设计模式和 Blend 中,但它不会在运行时显示。
您必须将图像的"构建操作"设置为"资源"也许可以更改为源=资源/XXX.png"