【问题标题】:Windows Store app failed to create style BasedOn shared styleWindows 应用商店应用无法创建样式 BasedOn 共享样式
【发布时间】:2015-03-02 13:34:36
【问题描述】:

我有一个 Windows 8.1 应用程序。

在 Project.Shared 中有 ResourceDictionary SharedResources.xaml 基本样式,

<Style x:Key="CommonLayerListItemStyle" TargetType="TextBlock">
    <Setter Property="FontFamily" Value="Segoe WP" />
    <Setter Property="Foreground" Value="{StaticResource UnselectBrush}" />
    <Setter Property="VerticalAlignment" Value="Stretch" />
</Style>

在 Windows Phone 应用程序中是 StyleResources.xaml 带有基于此的样式

<Style x:Key="LayerListItemStyle"   
       BasedOn="{StaticResource CommonLayerListItemStyle}"
       TargetType="TextBlock">
    <Setter Property="FontSize" Value="20" />        
</Style>

在 Windows 应用程序StyleResources.xaml 中相同:

<Style x:Key="LayerListItemStyle"
       BasedOn="{StaticResource CommonLayerListItemStyle}"
       TargetType="TextBlock">
    <Setter Property="FontSize" Value="28" />
    <Setter Property="Margin" Value="42,0,0,0" />
</Style>

所有样式都在共享项目中创建的 UserControl 中使用。 我这样做是为了覆盖不同平台上的 FontSize。

我合并了 App.xaml 中的所有字典

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Styles/SharedResources.xaml" />
    <ResourceDictionary Source="Styles/StyleResources.xaml" />
</ResourceDictionary.MergedDictionaries>

但是我的应用程序没有以未处理的异常开始 Cannot find a Resource with the Name/Key CommonLayerListItemStyle [Line: 10 Position: 37]

为什么会这样?

【问题讨论】:

标签: xaml windows-store-apps winrt-xaml resourcedictionary win-universal-app


【解决方案1】:

我有同样的问题。您需要将 SharedResources.xaml 直接合并到 StyleResources.xaml 中,并且只从 App.xaml 中引用 StyleResources.xaml。

这是一个完整的例子: http://blog.craftingbytes.com/2015/05/resource-sharing-in-windows-universal.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-24
    • 1970-01-01
    • 1970-01-01
    • 2020-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多