Skip to content

字体 ​

默认字体 ​

xml
<FontFamily x:Key="DefaultFontFamily">Segoe UI, Inter, Noto Sans, Cantarell, SF Pro Text, sans-serif</FontFamily>

使用AvaloniaFluentUI.Fonts字体库 ​

安装字体库

powershell
dotnet add package AvaloniaFluentUI.Fonts
  • 使用AvaloniaFluentUI.Fonts命名空间
  • 通过WithFont使用字体
csharp
using Avalonia;
using System;
using AvaloniaFluentUI.Fonts;

namespace Demo;

sealed class Program
{
    // Initialization code. Don't use any Avalonia, third-party APIs or any
    // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
    // yet and stuff might break.
    [STAThread]
    public static void Main(string[] args) => BuildAvaloniaApp()
        .StartWithClassicDesktopLifetime(args);

    // Avalonia configuration, don't remove; also used by visual designer.
    public static AppBuilder BuildAvaloniaApp()
        => AppBuilder.Configure<App>()
            .UsePlatformDetect()
#if DEBUG
            .WithDeveloperTools()
#endif
            .WithFont()
            .LogToTrace();
}

替换字体 ​

xml
<Application.Resources>
    <ResourceDictionary>
        <FontFamily x:Key="DefaultFontFamily">你的字体路径</FontFamily>
    </ResourceDictionary>
</Application.Resources>

基于 MIT 许可发布