c# - 使用 ImageBrush 启动时程序崩溃

标签 c# wpf visual-studio xaml imagebrush

我正在尝试在 Visual Studio 2013 中创建一个带有 ImageBrush 背景的非常简单的窗口,作为对更复杂项目的测试。图像显示在设计器中,但是当我启动它时程序崩溃了。这是 XAML:

<Window x:Class="BackgroundTest.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 Name="grid1">
        <Grid.Background>
            <ImageBrush ImageSource="/Images\Koala.jpg" Stretch="Fill"/>
        </Grid.Background>
    </Grid>
</Window>

以及基本上空的 C#(就像我说的,只是一个测试):

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace BackgroundTest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
}

我确信它与 ImageBrush 有关,如果我删除 XAML 的该部分,程序将按预期运行一个空白窗口。谁能帮我让它运行起来?

这是调试输出: “System.Windows.Markup.XamlParseException”类型的第一次机会异常出现在PresentationFramework.dll中

其他信息:“为‘System.Windows.Baml2006.TypeConverterMarkupExtension’提供值引发了异常。”行号“7”和行位置“14”。

最佳答案

图像的构建操作可能设置为内容。将其更改为资源。

关于c# - 使用 ImageBrush 启动时程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21296429/

相关文章:

asp.net - 这两个有什么区别......?

c - 静态/动态库与 .so 库?

WPF:DLL中的等效应用程序资源

c# - 算法进度回调

wpf - 当我在 Treeview 项目中使用它时,内容绑定(bind)不适用于文本 block

c# - 了解 async/await 以管理多个客户端

visual-studio - Unity 类型或命名空间名称 'Spatial Tracking' 命名空间中不存在 'UnityEngine'

c# - Base64UrlEncode 的使用语句

c# - 从 ASP.Net NULL 值输入到 MySQL

c# - 通过nuget包添加代码分析规则集