WPF应用程序的默认字体系列是什么?

时间:2010-11-10 06:43:14

标签: .net wpf

WPF应用程序的默认字体系列是什么?这个系统依赖吗?我在我的系统上找到了 Tahoma

如果我创建了一个控件,那么将设​​置什么是默认的控制字体家族?

3 个答案:

答案 0 :(得分:40)

“默认”字体是当前操作系统的当前系统字体。 Tahoma是Windows XP的默认系统字体,在Vista,Windows 7上是Segoe UI。

答案 1 :(得分:4)

在Windows 8上,似乎后备字体是Segoe UI,具有0.9基线和1.2行间距。

Simulating WPF default font

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

答案 2 :(得分:1)

您可以从默认值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);
    }