Change global application font in a Windows 8.1 app

左心房为你撑大大i 提交于 2019-12-11 03:32:13

问题


There are lots of articles online about how to embed custom fonts, create font styles and apply them to controls. But how can one override the global application font such that each control uses that font instead of setting the FontFamily property manually for each control. In my case, I do not wish to use a custom font as the global font but a system font such as Tahoma or Calibri.


回答1:


In winrt default Fontfamily for all controls ContentPresenter is Segoe Ui and its key is ContentControlThemeFontFamily.

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

1) Go to StandardStyles.xaml

2) Add <FontFamily x:Key="ContentControlThemeFontFamily">Tahoma</FontFamily>in default and Highcontrast resourcedictionary of ThemeDictionaries like below.

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



来源:https://stackoverflow.com/questions/23150457/change-global-application-font-in-a-windows-8-1-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!