【发布时间】:2017-02-27 16:11:43
【问题描述】:
我创建了一个新的 Windows Phone 8 (Silverlight) 项目。 添加了Themes文件夹,在该文件夹中添加了两个资源字典,一个包含solidcolorbursh,一个包含colors。
我在 App.xaml 中合并了这两个资源字典
在 MainPage.xaml 中,我使用了一个solidcolorbursh 作为网格背景。
代码片段:
App.xaml:
<Application.Resources>
<ResourceDictionary x:Key="mainStyle">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/resTest;component/Themes/MyColors.xaml"></ResourceDictionary>
<ResourceDictionary Source="/resTest;component/Themes/MyStyles.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<local:LocalizedStrings xmlns:local="clr-namespace:resTest" x:Key="LocalizedStrings"/>
</ResourceDictionary>
</Application.Resources>
MainPage.xaml:
<Grid x:Name="LayoutRoot" Background="{StaticResource RedSolidColorBrush}">
</Grid>
MyColors.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Color x:Key="RedColor">#FFFF0000</Color>
</ResourceDictionary>
MyStyles.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<SolidColorBrush x:Key="RedSolidColorBrush" Color="{StaticResource RedColor}"></SolidColorBrush>
</ResourceDictionary>
抛出异常:
块引用
System.Windows.ni.dll 中的“System.Windows.Markup.XamlParseException” 它显示运行时错误:
抛出异常:“System.Windows.Markup.XamlParseException”在 System.Windows.ni.dll
附加信息:找不到具有名称/键的资源 RedColor [行:14 位置:44]
我哪里错了?
参考文献: https://msdn.microsoft.com/en-us/library/cc903952(VS.95).aspx
Referencing a merged resource dictionary in windows phone seven failing
【问题讨论】:
标签: c# xaml silverlight windows-phone-8 windows-phone