.net WPF 应用程序的默认字体系列是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4141877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the default font family of a WPF application?
提问by Ashish Ashu
What is the default font family of a WPF application? Is this system dependent? I found Tahomaon my system.
WPF 应用程序的默认字体系列是什么?这个系统依赖吗?我在我的系统上找到了Tahoma。
If I create a control then what will be the default fontfamily of control is set?
如果我创建一个控件,那么控件的默认字体系列将设置什么?
回答by bitbonk
The "default" font is the current system font of your current OS. Tahoma is the default system font of Windows XP, on Vista, Windows 7 it is Segoe UI.
“默认”字体是当前操作系统的当前系统字体。Tahoma 是 Windows XP 的默认系统字体,在 Vista、Windows 7 上是 Segoe UI。
回答by Robert Gowland
On Windows 8, it seems like the fallback font is Segoe UI with a 0.9 baseline and 1.2 line spacing.
在 Windows 8 上,后备字体似乎是 Segoe UI,基线为 0.9,行距为 1.2。
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:clr="clr-namespace:System;assembly=mscorlib">
<Page.Resources>
<clr:String x:Key="someText">The quick brown fox, ABCD, 1234567890, /@#</clr:String>
<SolidColorBrush x:Key="lightColor">#bbbbbb</SolidColorBrush>
<SolidColorBrush x:Key="darkColor">#000000</SolidColorBrush>
<FontFamily x:Key="default">non existent font</FontFamily>
<FontFamily x:Key="segoe">Segoe UI</FontFamily>
<FontFamily x:Key="segoe_base" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/composite-font"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib"
Baseline="0.9"
LineSpacing="1.2">
<FontFamily.FamilyNames>
<s:String x:Key="en-US" >Baseline Segoe UI</s:String>
</FontFamily.FamilyNames>
<FontFamily.FamilyMaps>
<FontFamilyMap Target="Segoe UI" />
</FontFamily.FamilyMaps>
</FontFamily>
</Page.Resources>
<StackPanel Margin="10" Width="250">
<TextBlock TextWrapping="Wrap">Segoe UI with a baseline of 0.9 and line spacing of 1.2 lines up with the default font</TextBlock>
<Grid Margin="5">
<TextBlock Foreground="{StaticResource darkColor}" TextWrapping="Wrap" FontSize="20" FontFamily="{StaticResource default}" Text="{StaticResource someText}"/>
<TextBlock Foreground="{StaticResource lightColor}" TextWrapping="Wrap" FontSize="20" FontFamily="{StaticResource segoe_base}" Text="{StaticResource someText}"/>
</Grid>
<TextBlock Margin="0,10,0,0" TextWrapping="Wrap">Segoe UI with the default baseline and line spacing does not line up with the default font</TextBlock>
<Grid Margin="5">
<TextBlock Foreground="{StaticResource darkColor}" TextWrapping="Wrap" FontSize="20" FontFamily="{StaticResource default}" Text="{StaticResource someText}"/>
<TextBlock Foreground="{StaticResource lightColor}" TextWrapping="Wrap" FontSize="20" FontFamily="{StaticResource segoe}" Text="{StaticResource someText}"/>
</Grid>
</StackPanel>
</Page>
回答by Smagin Alexey
You can take it from default value of DependencyProperty. For example, you create custom control, which will be draw text using DrawingContext and you want set default value for FontFamily, you can declare DependencyPropertysuch way:
您可以从 的默认值中获取它DependencyProperty。例如,您创建自定义控件,它将使用 DrawingContext 绘制文本,并且您想为 FontFamily 设置默认值,您可以DependencyProperty这样声明:
public static readonly DependencyProperty FontFamilyProperty = DependencyProperty.Register(nameof(FontFamily), typeof(FontFamily), typeof(MyControl), new FrameworkPropertyMetadata(TextBlock.FontFamilyProperty.DefaultMetadata.DefaultValue, FrameworkPropertyMetadataOptions.AffectsRender));
public FontFamily FontFamily
{
get => (FontFamily)GetValue(FontFamilyProperty);
set => SetValue(FontFamilyProperty, value);
}


