gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 10:51:23 24 4
gpt4 key购买 nike

我正在尝试在 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 的那部分,程序将按预期运行一个空白窗口。谁能帮我让它运行起来?

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

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

最佳答案

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

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com