maui

How do I use a custom font?


I have a Maui app where I am successfully using custom fonts. However, in the Maui Toolkit Snackbar, setting the font is done with a font object, not the string for font family.

How can I load up a Font object from my custom font?

    var snackbarOptions = new SnackbarOptions
    {
        // this is how you set the font according to samples
        Font = Microsoft.Maui.Font.SystemFontOfSize(14),
        // FontFamily is not valid. Custom fonts are usually set like this
        FontFamily = "MyCustomFont" 
    };

Solution

  • Found the solution:

    Font = Font.OfSize("MyCustomFontName", 14),