如何设置WPF窗口的背景?

sok*_*vic 30 wpf background

我有一个简单的WPF窗口.我打算将它的背景设置为我作为嵌入式资源项目添加的图像之一.这是我试过的:

<Window x:Class="A_Boggle.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="A-Boggle" Height="300" Width="625" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" Name="Game">
<Window.Background>
    <ImageBrush ImageSource="background.jpg"></ImageBrush>
</Window.Background>
<Grid>
</Grid>
Run Code Online (Sandbox Code Playgroud)

但有了这个,我总是得到这个:"错误1文件splash.jpg不是项目的一部分,或者它的'Build Action'属性没有设置为'Resource'."

有任何想法吗?

Aar*_*ver 20

转到VS中的图像并将项目设置为资源.右键单击 - >属性 - >构建操作 - >资源

更新:

如果它在文件夹中,则需要更改路径.即...资源/ background.jpg

  • @sokolovic,如果有效,请不要忘记接受答案 (5认同)