<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication3"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Image Source="Image/desktop.jpg"></Image>
</Grid>
</Window>
效果:
这里需要注意的一点是属性需要设置一下:
这样图片编译后就会以二进制的方式保存在exe文件里面了,即使我们把image图片删掉,点击exe文件也能正常显示图片。
如果我们把生成操作改为复制到输出目录 ->始终复制,这样的话,如果删掉图片是无法显示的。