Skip to content

How to change the FontFamily of MenuItem #16002

Answered by Rogersbin
Rogersbin asked this question in Q&A
Discussion options

You must be logged in to vote

Fortunately,I find an useful solution.

  • Add AppBuilderExtension.cs
using Avalonia.Media;

namespace X04.Desktop;

public static class AppBuilderExtension
{
    public static AppBuilder WithFontBySourceHanSansCN(this AppBuilder appBuilder)
    {
        var uri = "avares://Quick.AvaloniaFonts.SourceHanSansCN/Assets/Fonts#Source Han Sans CN";
        return appBuilder.With(new FontManagerOptions()
        {
            DefaultFamilyName = uri,
            FontFallbacks = new[] { new FontFallback { FontFamily = new FontFamily(uri) } }
        });
    }
}
  • Then replace WithInterFont() with WithFontBySourceHanSansCN() in Program.cs.
using Avalonia;
using Avalonia.Media;
using Avalonia.React…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by Rogersbin
Comment options

You must be logged in to vote
2 replies
@Rogersbin
Comment options

@timunie
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants