0
此问题最初公布为here。尽管OP接受了解决方案,但我仍然无法弄清楚导致异常的原因。我做了一些进一步的测试并失败了。分配给属性时XamlParseException
的代码非常简单 - Windows Phone的应用程序只使用XAML内容:
<phone:PhoneApplicationPage.Resources>
<Image x:Key="IButton" Source="Resources/firstImage.png"/>
</phone:PhoneApplicationPage.Resources>
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Button x:Name="first" Content="{StaticResource IButton}" VerticalAlignment="Center" Grid.Row="0"/>
<Button x:Name="second" VerticalAlignment="Center" Grid.Row="1">
<Image Source="Resources/firstImage.png"/>
</Button>
</Grid>
乍看之下,一切正常,VS设计师正确显示两个Button里面的图像。当我试图剥夺应用程序时,我得到XamlParseException:
未能分配给属性'System.Windows.Controls.ContentControl.Content'。
问题涉及第一个按钮 - 第二个是没有问题
很奇怪运行。我尝试过改变Build Action(资源/内容),清理项目,但没有成功。
相反,非常相似的WPF应用程序没有问题。你刚打运行,看到两个按钮:
<Window.Resources>
<Image x:Key="IButton" Source="Resources/firstImage.png"/>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Button x:Name="first" Content="{StaticResource IButton}" VerticalAlignment="Center" Grid.Row="0"/>
<Button x:Name="second" VerticalAlignment="Center" Grid.Row="1">
<Image Source="Resources/firstImage.png"/>
</Button>
</Grid>
大家有一个想法是什么可能是错的?这两个应用程序(WP/WPF)你can get here。
这不是问题所在。第二个按钮没有问题。你的代码当然会起作用。问题涉及第一个按钮以及它不起作用的原因。第二个按钮仅用于检查图像文件是否存在等。 – Romasz