【问题标题】:Change global application font in a Windows 8.1 app在 Windows 8.1 应用程序中更改全局应用程序字体
【发布时间】:2014-04-18 08:34:54
【问题描述】:

网上有很多关于如何嵌入自定义字体、创建字体样式并将它们应用到控件的文章。但是如何覆盖全局应用程序字体,以便每个控件都使用该字体,而不是为每个控件手动设置 FontFamily 属性。就我而言,我不希望使用自定义字体作为全局字体,而是使用系统字体,例如 Tahoma 或 Calibri。

【问题讨论】:

    标签: c# xaml windows-runtime winrt-xaml windows-8.1


    【解决方案1】:

    在 winrt 中,所有控件 ContentPresenter 的默认 Fontfamily 为 Segoe Ui,其键为 ContentControlThemeFontFamily

    -*您可以从资源字典中更改或覆盖按钮、组合框项、列表框项等的字体系列,因为它们具有模板属性(contenpresenter 或 itempresenter)

    1) 转到 StandardStyles.xaml

    2) 在 ThemeDictionaries 的默认和高对比度资源字典中添加<FontFamily x:Key="ContentControlThemeFontFamily">Tahoma</FontFamily>,如下所示。

       <ResourceDictionary.ThemeDictionaries>
        <ResourceDictionary x:Key="Default">
            <x:String x:Key="BackButtonGlyph">&#xE071;</x:String>
            <x:String x:Key="BackButtonSnappedGlyph">&#xE0BA;</x:String>
            <FontFamily x:Key="ContentControlThemeFontFamily">Tahoma</FontFamily>
        </ResourceDictionary>
        <ResourceDictionary x:Key="HighContrast">
            <FontFamily x:Key="ContentControlThemeFontFamily">Tahoma</FontFamily>
            <x:String x:Key="BackButtonGlyph">&#xE071;</x:String>
            <x:String x:Key="BackButtonSnappedGlyph">&#xE0C4;</x:String>
        </ResourceDictionary>
    </ResourceDictionary.ThemeDictionaries>
    

    但 Textblock 没有模板属性,因此您可以如下更改其属性

    1.第一种方法

     <TextBlock  FontFamily="{StaticResource ContentControlThemeFontFamily }" >dfdsfsdf</TextBlock>
    

    2。第二种方法

    <Page
    x:Class="App3.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App3"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
    mc:Ignorable="d" FontFamily="{StaticResource ContentControlThemeFontFamily}">
    <Grid>
        <TextBlock>Hello World</TextBlock>
    </Grid>
    

    【讨论】:

    • 您还可以使用{ThemeResource} XAML 标记扩展,以便在用户在默认、高对比度和其他内置主题之间切换时更新您的主题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-11
    • 2015-12-31
    • 1970-01-01
    • 2015-12-19
    • 2021-10-26
    • 1970-01-01
    • 2013-03-10
    相关资源
    最近更新 更多