Search code examples
wpffont-family

Multiple font family values in WPF


To ensure which font will be used as a fallback if the primary font is not available on the user's OS.

Is it possible to specify multiple font family values in WPF, similar to CSS?

For instance:

font-family: "Times New Roman", Georgia, Serif;

Solution

  • Yes, you can: FontFamily = "Times New Roman, Georgia, Serif":

    Extract from the XAML values of TextBlock.FontFamily property documentation:

    fontFamilyNamesList
    A string specifying multiple font family names, each separated by a comma (any white space following a comma is ignored). The first font family specified serves as the primary font family; subsequent font families serve as fallback families to be used in cases where the primary font family is unavailable or not applicable. For example, "Arial, Century Gothic" specifies Arial as the primary font family, with Century Gothic as the fallback font family.

    Example, Georgia doesn't contains chinese font.

    <StackPanel>
        <TextBlock FontSize = "20" FontFamily = "Georgia">English 中文</TextBlock>
        <TextBlock FontSize = "20" FontFamily = "Georgia, FangSong">English 中文</TextBlock>
        <TextBlock FontSize = "20" FontFamily = "FangSong">English 中文</TextBlock>
    </StackPanel>
    

    enter image description here