https://blog.csdn.net/saloon_yuan/article/details/9137477
WPF下将背景设置成图片的步骤如下:
先来看一下未添加背景图片前的界面:
1:将图片拷贝至工程下面
2:双击[Resources.resx],左边主编辑框中点击[Add Resource] ,选择刚才拷贝的图片的路径。
3:添加完成之后,文件夹images会出现在工程中,图片也包含进来了,右键crystal.jpg进入Properties,在Properties中的 Build Action中 将其设为Resource。
4:xaml代码修改如下:
-
<Window x:Class="WpfBackGroundImage.MainWindow"
-
xmlns=
"http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-
xmlns:x=
"http://schemas.microsoft.com/winfx/2006/xaml"
-
Title=
"MainWindow"
Height=
"350"
Width=
"525">
-
<Grid>
-
-
</Grid>
-
</Window>
|
|
V
-
<Window x:Class="WpfBackGroundImage.MainWindow"
-
xmlns=
"http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-
xmlns:x=
"http://schemas.microsoft.com/winfx/2006/xaml"
-
Title=
"MainWindow"
Height=
"350"
Width=
"525">
-
<Grid>
-
<Image Source="Images\Crystal.jpg" Stretch="Fill"/>
-
</Grid>
-
</Window>
5:工程Clean之后,运行结果如下: