我遇到了以下异常:
显然,运用
'PresentationFramework.dll' 中的 'System.Windows.Markup.XamlParseException'
。我找到了这个帖子(链接)。显然,运用
CTRL+ALT+E
方法并检查所有异常并不能解决我的问题,或者是我使用方法不正确。我检查了所有异常,它导致我找到了我MainWindow的InitializedComponent()
函数,问题就在这里。您有什么建议吗?我会将我所有的XAML
代码:MainWindow
发送给您。<Window x:Class="DPCKOU_prog3hf_pong.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DPCKOU_prog3hf_pong"
mc:Ignorable="d"
Title="PongGame" Height="406" Width="717"
Loaded="Window_Loaded"
KeyDown="Window_KeyDown"
>
<Canvas Background="{StaticResource fieldBGSP}">
<Rectangle Canvas.Left="{Binding Path=Pad.Area.X}"
Canvas.Top="{Binding Path=Pad.Area.Y}"
Width="{Binding Path=Pad.Area.Width}"
Height="{Binding Path=Pad.Area.Height}"
Fill="{StaticResource RectangleFill}"/>
<Ellipse Canvas.Left="{Binding Path=Ball.Area.X}"
Canvas.Top="{Binding Path=Ball.Area.Y}"
Width="{Binding Path=Ball.Area.Width}"
Height="{Binding Path=Ball.Area.Height}"
Fill="{StaticResource EllipseFill}"/>
</Canvas>
</Window>
还有我的 App.xaml
文件:
<Application x:Class="DPCKOU_prog3hf_pong.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DPCKOU_prog3hf_pong"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
StartupUri="MainWindow.xaml">
<Application.Resources>
<SolidColorBrush x:Key="RectangleFill" Color="#FF0F4228"/>
<SolidColorBrush x:Key="EllipseFill" Color="#FF207CBB"/>
<ImageBrush x:Key="fieldBGMP" ImageSource="pack://application:,,,/texturesExport/background.png"/>
<ImageBrush x:Key="fieldBGSP" ImageSource="pack://application:,,,/texturesExport/pong_ingameSP.png"/>
</Application.Resources>
</Application>
编辑
我在Canvas
之前的孤立的>
符号处遇到错误。在编辑器中,背景图像显示正常。不知道是什么原因导致了这个问题。
我使用了pack uri
方法更新了我的代码。
Background
属性中删除末尾的空格:<Canvas Background="{StaticResource fieldBGSP}">
。 - Hakan Fıstık