【发布时间】:2012-04-03 07:23:20
【问题描述】:
我在 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 文件中添加资源。
有人可以在这里指出解决方案吗?
【问题讨论】:
-
首先,确保文件“MyResources.xaml”存在且其“Build Action”设置为“Resource”
-
我不认为资源需要作为构建操作,因为我只是在页面构建操作上运行它
标签: windows-phone-7 resourcedictionary mergeddictionaries