【问题标题】:MergedDictionaries can not be referenced from App.xaml无法从 App.xaml 引用 MergedDictionaries
【发布时间】:2014-11-11 16:43:36
【问题描述】:

为了更好的组织和可读性,我的样式被分隔在单独的文件中。我的 App.xaml 中引用了所有文件。某些样式是BasedOn 其他样式,因此我将它们按正确的顺序放置,以便在从属样式之前加载继承的样式。但是,我在引用字体样式的 XAML 视图上仍然收到以下错误,例如...Cannot find a Resource with the Name/Key SourceSansPro-Light

有人能告诉我为什么找不到这个名称/密钥吗?这是相关代码。

App.xaml

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Common/Styles/StyleResources.xaml" />
            <ResourceDictionary Source="Common/Styles/InputStyles.xaml" />                
        </ResourceDictionary.MergedDictionaries>            
    </ResourceDictionary>
</Application.Resources>

StyleResources.xaml

<ResourceDictionary.ThemeDictionaries>
    <ResourceDictionary x:Key="Light">
        <SolidColorBrush x:Key="TextBoxBackgroundBrush" Color="White"/>
    </ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>

<FontFamily x:Key="SourceSansPro-Light">../../Assets/Fonts/SourceSansPro-Light.otf#Source Sans      Pro</FontFamily>

<Style x:Key="TextBlockStyle" TargetType="TextBlock" BasedOn="{StaticResource BaseTextBlockStyle}">
    <Setter Property="FontSize" Value="18"/>
    <Setter Property="FontFamily" Value="{StaticResource SourceSansPro-Semibold}" />
</Style>

InputStyles.xaml

<Style x:Key="SecondaryTextStyle" TargetType="TextBlock" BasedOn="{StaticResource TextBlockStyle}">
   <Setter Property="FontFamily" Value="{StaticResource SourceSansPro-Light}"/>
</Style>

HomePage.xaml(在此视图中调用样式 SourceSansPro-Light)

<Page.Resources>
    <Style x:Name="InfoBodyTextStyle" TargetType="TextBlock">
        <Setter Property="FontFamily" Value="{StaticResource SourceSansPro-Light}"/>
    </Style>

【问题讨论】:

  • 你可以尝试在InputStyles.xaml 中不使用SourceSansPro-light 运行吗?
  • 我相信this question 有您想要的答案。不能在 InputStyles.xaml 中使用 SourceSansPro-Light,因为 InputStyles.xaml 的解析独立于 StyleResources.xaml。您必须将 StyleResources.xaml 合并到 InputStyles.xaml。
  • @DecadeMoon,如果您发表评论作为答案,我会接受它,因为它是针对我的问题的。感谢您的帮助。

标签: xaml windows-phone-8.1


【解决方案1】:

请试试这个代码。

<Style TargetType="TextBlock">
    <Setter Property="Foreground" Value="#FF64CCEF"/>        
    <Setter Property="SnapsToDevicePixels" Value="True"/>       
    <Setter Property="FontFamily" Value="{DynamicResource FontFamilyResource}"/>                     
</Style>

<FontFamily x:Key="FontFamilyResource">/ApplicationName(SolutionName);component/Resources/Fonts/#Vladimir Script</FontFamily>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    相关资源
    最近更新 更多