本文的方法适用于 11.0 的 Avalonia 版本
只需在 Program.cs 的 BuildAvaloniaApp 方法里面配置 X11PlatformOptions 即可,代码如下
.With(new X11PlatformOptions() { RenderingMode = new List<X11RenderingMode>() { X11RenderingMode.Software } }
修改之后的 Program.cs 大概代码如下
using System;using System.Collections.Generic;
using Avalonia;using Avalonia.Media;
namespace NelkiwalweawhabairJewugekayfaylugere.Desktop;
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() .WithInterFont() .LogToTrace() // 修复麒麟丢失字体 .With(new FontManagerOptions() { DefaultFamilyName = "Noto Sans CJK SC", FontFallbacks = [ new FontFallback { FontFamily = "文泉驿正黑" }, new FontFallback { FontFamily = "DejaVu Sans" }, ], }) .With(new X11PlatformOptions() { RenderingMode = new List<X11RenderingMode>() { X11RenderingMode.Software } });
}
以上的代码设置字体是为了解决在麒麟系统无法显示中文的问题或运行进程失败的问题。详细请看 dotnet 解决 UNO 在 OpenKylin 麒麟系统运行找不到默认字体启动失败
本文代码放在 github 和 gitee 上,可以使用如下命令行拉取代码
先创建一个空文件夹,接着使用命令行 cd 命令进入此空文件夹,在命令行里面输入以下代码,即可获取到本文的代码
git initgit remote add origin https://gitee.com/lindexi/lindexi_gd.gitgit pull origin 8402eaca48804ec2418b459f540e5e48d1109a23
以上使用的是 gitee 的源,如果 gitee 不能访问,请替换为 github 的源。请在命令行继续输入以下代码,将 gitee 源换成 github 源进行拉取代码
git remote remove origingit remote add origin https://github.com/lindexi/lindexi_gd.gitgit pull origin 8402eaca48804ec2418b459f540e5e48d1109a23
获取代码之后,进入 AvaloniaIDemo/NelkiwalweawhabairJewugekayfaylugere 文件夹,即可获取到源代码
更多 Avalonia 以及 X11 等相关技术,请参阅 博客导航

本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。 欢迎转载、使用、重新发布,但务必保留文章署名 林德熙 (包含链接: https://blog.lindexi.com ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请与我 联系。