我在 WP7 Mango 中遇到 ResourceDictionary 的问题。
我在互联网上能找到的大部分内容都很简单:
1) 带有正文的 Xaml 文件:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="TextBlockStyle1" TargetType="TextBlock">
<Setter Property="Foreground" Value="Orange"/>
<Setter Property="FontSize" Value="24"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
</Style>
</ResourceDictionary>
2) 添加到 App.xaml 如下:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="MyResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
不知道为什么它不起作用。当这样做时,我得到异常:
'ResourceDictionary' 类型位于 ResourceDictionary 内部,并且没有键。
当我在步骤 2 中将 ked 添加到第二个 xaml 行时,它会运行,但会因未指定的错误而崩溃。看起来它没有从 MyResources.xaml 文件中添加资源。
有人可以在这里指出解决方案吗?