WPF Image控件 Source绑定相对路径方法

(1)

/Test:图片所对应的程序集名称(工程名称);

component/img/close.png:component固定前缀;
/后面是图片相对路径 如component/img/close.png;

这样我们在编译后的bin目录下可以看到,没有图片文件,因为上面我们是把图片做成资源文件了,图片等资源文件会自动编译到dll或者exe里面了。

<Image Margin="30,9,0,0" Name="image1" Stretch="Fill" Height="29" HorizontalAlignment="Left" VerticalAlignment="Top" Width="62" Grid.Row="1" Source="/testModel;component/img/close.png" />