关于样式和资源的问题:Cannot find a resource with the name XXX.
本人Windows 移动开发新手,用Win8.1+VS2013,遇到一个问题请教前辈们。
在项目中,我添加了一个Themes文件夹,然后先添加一个资源字典Share.xaml,其中定义了两个资源供其它资源字典使用:
<x:Double x:Key="LargeButtonFontSize">26</x:Double>
<x:Double x:Key="NormalTextSize">28</x:Double>
然后再向Themes文件夹添加两个资源字典,分别是ButtonStyle.xaml 和 TextBlockStyle.xaml,
它们两使用Share.xaml中定义的资源:
<Style TargetType="Button">
<Setter Property="FontSize" Value="{StaticResource LargeButtonFontSize}"/>
</Style>
<Style TargetType="TextBlock">
<Setter Property="FontSize" Value="{StaticResource NormalTextSize}"/>
</Style>
最后把这三个资源字典合并到App资源字典中:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/Share.xaml"/>
<ResourceDictionary Source="Themes/ButtonStyle.xaml"/>
<ResourceDictionary Source="Themes/TextBlockStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
编译程序OK,但运行时就出现找不到名为LargeButtonFontSize的资源的错误提示,求解!