36

What is the default font family of a WPF application? Is this system dependent? I found Tahoma on my system.

If I create a control then what will be the default fontfamily of control is set?

4 Answers 4

43

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.

3
  • 9
    That is the default font you type with but not the font of the UI (i.e. the font used in the menues and buttons of Word).
    – bitbonk
    Nov 10, 2010 at 6:57
  • Any idea for Windows 8? Aug 30, 2014 at 18:34
  • Segoe UI is also default in Win10 and Win11
    – Neur0
    Jul 17, 2023 at 14:36
4

On Windows 8, it seems like the fallback font is Segoe UI with a 0.9 baseline and 1.2 line spacing.

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>
1
  • 6
    It's worth mentioning that this font family comes from SystemFonts.MessageFontFamily static property. So if you ever need to use it somewhere in your app - you should read it from there instead of constructing the new FontFamily instance by yourself.
    – torvin
    May 18, 2017 at 3:52
2

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 DependencyProperty such way:

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);
    }
0

To answer the question correctly, Segoe UI is the default FontFamily for WPF apllications.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.