Defining a custom FontFamily with several font files


  • I'm trying to define a custom font with multiple weights/variants. I can define a single-file font in XAML like so:

        <FontFamily x:Key="Cousine">/Fonts/Cousine-Regular.ttf#Cousine</FontFamily>

    But I have several other font files that I would like to be used where appropriate:

    • Cousine-Bold.ttf
    • Cousine-BoldItalic.ttf
    • Cousine-Italic.ttf

    How do I define a font family that uses the different fonts for the different font weights/variants?

    Wednesday, June 04, 2014 2:53 AM


  • You can do this:

            <FontFamily x:Key="Cousine">/Fonts/Cousine-Regular.ttf#Cousine</FontFamily>
            <FontFamily x:Key="Cousine-Italic">/Fonts/Cousine-Italic.ttf#Cousine</FontFamily>
            <FontFamily x:Key="Cousine-Bold">/Fonts/Cousine-Regular.ttf#Cousine</FontFamily>
            <FontFamily x:Key="Cousine-BoldItalic">/Fonts/Cousine-Regular.ttf#Cousine</FontFamily>
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <TextBlock FontFamily="{StaticResource Cousine}" FontSize="50">Hello</TextBlock>
            <TextBlock FontFamily="{StaticResource Cousine-Italic}" FontSize="50">Hello</TextBlock>

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, June 04, 2014 3:02 PM