尝试设置Window背景时,ImageBrush会抛出异常

尝试设置Window背景时,ImageBrush会抛出异常

问题描述:

我正在尝试将WPF窗口的背景设置为图像,但是当我尝试运行它时,我遇到了这个异常:

I'm trying to set the background of my WPF window to an image but I'm getting this exception when I try to run it:

PresentationFramework.dll中出现'System.Windows.Markup.XamlParseException'类型的第一次机会异常附加信息:'在'System.Windows.Baml2006.TypeConverterMarkupExtension'上提供值引发异常。'行号'8'和行位置'10'。

我不想将图像添加到项目中,因为我希望能够更改运行时的图像。我的意图是使用数据绑定在启动期间设置背景图片一旦我有这个位。

I don't want to add the image to the project, as I would like to be able to change the image at runtime. My intention is to use databinding to set the background picture during start-up once I have this bit working.

源代码:

<Window x:Class="ColinsTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Colin's Test Application" 
    WindowStyle="None"
    WindowState="Maximized">
<Window.Background>
    <ImageBrush 
        ImageSource="DeLaRue-Background.jpg"/>
</Window.Background>
<Grid></Grid>
</Window>

任何想法?谢谢

错了。它应设置为CONTENT not resource。

Wrong. It should be set to CONTENT not Resource.

包含在您的项目中(使用文件浏览器)

Include in your project (use the file explorer)


右键单击图像>属性>高级。

Right click on the image > Properties > Advanced.

构建操作:内容

复制到输出目录:始终复制。

Copy to Output Directory: Copy always.