How to set font weight and width in MAUI projects

MSCollege3000 120 Reputation points
2023-12-08T12:50:16.2666667+00:00

Hi. I haven't found any documentation on this.

There are fonts that have their weight and width variants embedded inside their .ttf file. In there, variants are named like e.g. FontName Light Condensed. Condensed value means shrunk in spacing and width.

How do you use those properties in xaml setters? How to set weight to a specific numeric value? How to fully specify name of an internal font variant in a setter?

<Setter Property="FontFamily" Value="SomeFontName Light Condensed"/>

<!-- or -->

<Setter Property="FontFamily" Value="SomeFontName"/>
<Setter Property="FontWeight" Value="..."/>
<Setter Property="FontWidth" Value="..."/>

I've only found this Microsoft page about Font usage in MAUI. If you can explain how to convert that text into a xaml style code I'll consider it an answer.

https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.font.weight?view=net-maui-8.0

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,796 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,970 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 36,951 Reputation points Microsoft Vendor
    2023-12-11T06:38:09.26+00:00

    Hello,

    Fonts in maui currently do not provide an API to directly modify the weight. MAUI provides several options for setting whether the font is bold or italic, but you can't specify specific properties.

    Please refer to Fonts in .NET MAUI for more details.

    FontAttributes, of type FontAttributes, which is an enumeration with three members: None, Bold, and Italic. The default value of this property is None.

    For more font family property support, there are already related issues on GitHub, please stay tuned to [Enhancement] Add an API to handle font families properly #1018.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful