System.Windows.Baml2006.TypeConverterMarkupExtension
本文关键字:TypeConverterMarkupExtension Baml2006 Windows System | 更新日期: 2023-09-27 18:21:38
你好,我确实遇到了一个问题,很多人似乎都遇到了,但我尝试了建议的解决方案,但都没有奏效。我有这样一个代码,它总是在Window.InitializeComponent()方法处引发异常(消息:"在'System.Windows.Baml2006.TypeConverterMarkupExtension'上提供值时引发异常")。这是我的Xaml代码:
<Window x:Class="SimpleMoving.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Name="SquareFighter" Height="392" Width="621" KeyDown="Window_KeyDown" KeyUp="Window_KeyUp" ResizeMode="CanMinimize">
<Canvas Name="MyCanvas">
<Rectangle Name="Box" Height="60" Canvas.Left="17" Stroke="Black" Canvas.Top="172" Width="30">
<Rectangle.Fill>
<ImageBrush ImageSource="pack://application:,,,/Resources/Peanut.png"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Name="Rec1" Height="30" Canvas.Left="908" Stroke="Black" Canvas.Top="50" Width="30">
<Rectangle.Fill>
<ImageBrush ImageSource="pack://application:,,,/Resources/Rock.png"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Height="30" Canvas.Left="908" Stroke="Black" Canvas.Top="110" Width="30">
<Rectangle.Fill>
<ImageBrush ImageSource="pack://application:,,,/Resources/Rock.png"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Height="30" Canvas.Left="908" Stroke="Black" Canvas.Top="169" Width="30">
<Rectangle.Fill>
<ImageBrush ImageSource="pack://application:,,,/Resources/Rock.png"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Height="30" Canvas.Left="908" Stroke="Black" Canvas.Top="229" Width="30">
<Rectangle.Fill>
<ImageBrush ImageSource="pack://application:,,,/Resources/Rock.png"/>
</Rectangle.Fill>
</Rectangle>
<Rectangle Height="30" Canvas.Left="908" Stroke="Black" Canvas.Top="289" Width="30">
<Rectangle.Fill>
<ImageBrush ImageSource="pack://application:,,,/Resources/Rock.png"/>
</Rectangle.Fill>
</Rectangle>
<Label Name="LevelLabel" Content="Level: 1" Canvas.Left="54" Canvas.Top="10" Height="38" Width="164" FontSize="20"/>
<Label Content="Shoot the squares back using WSDA!" Canvas.Left="180" Width="290" FontSize="16"/>
</Canvas>
</Window>
我不知道该怎么办。我希望你能帮忙。
很可能您在Resources文件夹下没有图像。
确保以下内容对XAML中使用的(Rock.png和Peanut.png)两个图像都有效:
- 图像是同一项目中的
added in project under Resources folder
- 图像的
Build Action
设置为Resource
此外,您可以尝试使用更详细的Pack URI定义:
"pack://application:,,,/SimpleMoving;component/Resources/Peanut.png"
和"pack://application:,,,/SimpleMoving;component/Resources/Rock.png"
,其中SimpleMoving是程序集的名称。