首页 文章

在Windows 8.1应用程序中更改全局应用程序字体

提问于
浏览
2

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

1 回答

  • 2

    在winrt中,默认Fontfamily适用于所有控件ContentPresenter是 Segoe Ui ,其键是 ContentControlThemeFontFamily .

    *-You can change or override fontfamily of button,comboboxitem,listboxitem etc from resourcedictionary because they have template property(contenpresenter or itempresenter)

    1)转到StandardStyles.xaml

    enter image description here

    2)在下面的ThemeDictionaries的默认和Highcontrast资源字典中添加 <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>
    

    But Textblock is not having template property so you can change its property like below

    1. First Method

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

    2. second method

    <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>
    

相关问题