locked
Defining a custom FontFamily with several font files

    Question

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

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

    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 4, 2014 2:53 AM

Answers

  • You can do this:

        <Page.Resources>
            <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>
        </Page.Resources>
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <StackPanel>
            <TextBlock FontFamily="{StaticResource Cousine}" FontSize="50">Hello</TextBlock>
            <TextBlock FontFamily="{StaticResource Cousine-Italic}" FontSize="50">Hello</TextBlock>
            </StackPanel>
        </Grid>


    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 4, 2014 3:02 PM
    Moderator