我正在使用 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 );
}