我试图创建一个非常简单的窗口,在Visual Studio 2013中使用ImageBrush背景作为更复杂项目的测试。该图像显示在设计器中,但程序在启动时崩溃。这里的XAML:使用ImageBrush启动时程序崩溃
<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();
}
}
}
我敢肯定它有事情做与图像刷,如果我删除部分XAML程序将按预期运行一个空白窗口。任何人都可以帮助我获得这个运行?
这里的调试输出: 型“System.Windows.Markup.XamlParseException”的第一次机会异常出现在PresentationFramework.dll
其他信息:System.Windows.Baml2006.TypeConverterMarkupExtension“上提供价值“抛出一个例外。“行号“7”和行位置“14”。
也许是因为图像来源?尝试“/Images/Koala.jpg” – JleruOHeP
我试过了多个图像源,并将图像添加到资源中。没有运气! –
您是否已将文件夹图像和图像添加到项目中?或者他们只是在那里?你有没有尝试像“C:\ Images \ koala.jpg”这样的源代码完整路径? – JleruOHeP