我的样式在单独的文件中分开,以便更好地组织和阅读。我的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(在此视图中调用style,SourceSansPro-Light)
<Page.Resources>
<Style x:Name="InfoBodyTextStyle" TargetType="TextBlock">
<Setter Property="FontFamily" Value="{StaticResource SourceSansPro-Light}"/>
</Style>
答案 0 :(得分:0)
请尝试此代码。
<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>