1

I’m working on an app that is delivered for both platform UWP and WinUI 3. In UWP, when I misspell or provide an invalid FontFamily, it seems to fall back to Segoe UI Variable. However, in WinUI 3, the fallback appears to be different and the Segoe UI Variable has different sizes in comparison to UWP.

In our UWP app, we explicitly set all TextBlock elements to use Segoe UI Variable, but when migrating to WinUI 3, we noticed that the "text box" size and layout appeared different. Interestingly, when we intentionally provide an invalid font family name in WinUI 3, the result visually matches what we had in UWP, suggesting that a different fallback font is being used compared to Segoe UI or Segoe UI Variable.

We tested various Segoe fonts (Segoe UI, Segoe UI Variable, Segoe UI Historic, etc.) but none of them visually matched the fallback font rendered when the FontFamily is invalid in WinUI 3.

Could you please clarify which font is used by default in WinUI 3 when an invalid or non-existent FontFamily is specified?

WinUI enter image description here

UWP enter image description here

WinUI enter image description here

UWP enter image description here

Thank you in advance!

1 Answer 1

0

You can check the default FontFamily like this:

<StackPanel Spacing="16">
    <StackPanel>
        <TextBlock x:Name="DefaultFontTextBlock" Text="ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789" />
        <TextBlock Text="{x:Bind DefaultFontTextBlock.FontFamily.Source}" />
    </StackPanel>
    <StackPanel>
        <TextBlock x:Name="InvalidFontTextBlock"
            FontFamily="INVALIDFONT"
            Text="ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789" />
        <TextBlock Text="{x:Bind InvalidFontTextBlock.FontFamily.Source}" />
    </StackPanel>
</StackPanel>

renders:

enter image description here

As you can see below, at least on my end, it falls back to Segoe UI when the FontFamily couldn't be resolved.

<StackPanel Orientation="Vertical">
    <TextBlock Text="ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789" />
    <TextBlock FontFamily="Segoe UI" Text="ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789" />
    <TextBlock FontFamily="INVALIDFONT" Text="ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789" />
</StackPanel>

enter image description here

I'm not sure if this is by design but, it seems that the TextBlock's height changes when the FontFamily fails.

TEST 1

<StackPanel Orientation="Horizontal">
    <TextBlock Text="ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789" />
    <TextBlock FontFamily="INVALIDFONT" Text="ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789" />
</StackPanel>

enter image description here

TEST 2

<Grid>
    <TextBlock Text="ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789" />
    <TextBlock FontFamily="INVALIDFONT" Text="ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789" />
</Grid>

enter image description here

TEST 3

<Grid>
    <TextBlock Text="ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789" />
    <TextBlock
        Margin="0,2,0,0"
        FontFamily="INVALIDFONT"
        Text="ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789" />
</Grid>

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Hello Andrew, thank you for the response. But what I need to know is the font used when you pass a Invalid Font (in your example it print "INVALIDFONT"), I need to know which font was used. Our first textblock will print Segoe UI, but when I put a invalid font, clearly is not using Segoe UI because the Height of the textblock changes.
Hi @RafaelNunes. I updated my answer with more info. It seems that the FontFamily falls back to Segoe UI after all.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.