我正在用Avalonia开发一个项目。作为图形编辑器的workingBase,我使用了以下允许绘制线条和矩形的项目:https://github.com/wieslawsoltes/LineEditor
我试图在Avalonia.Media.DrawingContext中编写文本,但在调用DrawingContext.DrawText方法时获得了NullRefereceException (在debbuger中,formattedText._platformImpl为null)。
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 );
}发布于 2022-01-27 16:19:36
您是否将AvaloniaUI NuGet更新为上一个版本?这个版本在这个存档的回购中是旧的。
在最近的示例https://github.com/wieslawsoltes/Core2D中快速搜索,您可以找到DrawText的出现
https://stackoverflow.com/questions/70864226
复制相似问题