尝试设置Window背景时,ImageBrush会抛出异常 [英] ImageBrush throws exception when trying to set Window background

查看:372
本文介绍了尝试设置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.

这篇关于尝试设置Window背景时,ImageBrush会抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆