【发布时间】:2014-02-14 07:39:04
【问题描述】:
这个问题最初是在here 发布的。尽管 OP 接受了解决方案,但我仍然无法弄清楚导致异常的原因。我做了一些进一步的测试,但失败了。
代码非常简单 - Windows Phone App 仅包含 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 设计器正确显示了两个带有图像的按钮。当我尝试部署应用程序时,我得到 XamlParseException:
未能分配给属性“System.Windows.Controls.ContentControl.Content”。
问题与第一个按钮有关 - 第二个按钮运行没有问题
很奇怪。我尝试更改构建操作(资源/内容),清理项目,但没有成功。
相反,非常相似的 WPF 应用程序可以正常工作。您只需点击 Run 并看到两个按钮:
<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。
【问题讨论】:
标签: c# wpf xaml windows-phone-7 windows-phone-8