1

我正在使用 Avalonia 开发一个项目。我将以下项目用作图形编辑器的工作基础,该项目允许绘制线条和矩形:https ://github.com/wieslawsoltes/LineEditor

我正在尝试在其中写入文本,Avalonia.Media.DrawingContext但我开始NullRefereceException调用DrawingContext.DrawText方法(在调试器中,formattedText._platformImpl为空)

public void DrawText(DrawingContext dc, TextShape textShape)
{            
    var brush = new SolidColorBrush(ToColor(textShape.Stroke));
    var point1 = new Point(textShape.TopLeft.X, textShape.TopLeft.Y);
    var typeface = new Typeface("Arial");
    var formattedText = new FormattedText("Hello", typeface, 12, TextAlignment.Left, TextWrapping.NoWrap, Size.Infinity);
    dc.DrawText(brush, point1, formattedText );
}
4

1 回答 1

1

您是否将 AvaloniaUI NuGet 更新到最新版本?此存档回购中的版本是旧的。

在最近的示例https://github.com/wieslawsoltes/Core2D中快速搜索,您可以找到 DrawText出现

于 2022-01-27T16:19:36.753 回答