C# 更改AvaloneEdit 5.x中的行高度

C# 更改AvaloneEdit 5.x中的行高度,c#,avalonedit,C#,Avalonedit,这是这篇文章的后续文章。既然你不能在那篇帖子里问问题,我必须在一篇新帖子里问同样的问题。以下是Peter Moore的帖子,他解释了如何增加线条高度 我想我已经实现了他所说的,但它似乎并没有增加实际编辑器文本的高度/位置,而是增加了文本应该在哪里的高度和行号。请看下图 关于如何确定编辑器文本的高度,有什么想法吗 在TextView.cs中: public static readonly DependencyProperty LineSpacingProperty = De

这是这篇文章的后续文章。既然你不能在那篇帖子里问问题,我必须在一篇新帖子里问同样的问题。以下是Peter Moore的帖子,他解释了如何增加线条高度

我想我已经实现了他所说的,但它似乎并没有增加实际编辑器文本的高度/位置,而是增加了文本应该在哪里的高度和行号。请看下图

关于如何确定编辑器文本的高度,有什么想法吗

在TextView.cs中:

    public static readonly DependencyProperty LineSpacingProperty =
        DependencyProperty.Register("LineSpacing", typeof(double), typeof(TextView),
        new FrameworkPropertyMetadata(1.0));

    public double LineSpacing
    {
        get { return (double)GetValue(LineSpacingProperty); }
        set { SetValue(LineSpacingProperty, value); }
    }
在VisualLine.cs(VisualLine.settextline)中:

然后在(VisualLine.GetTextLineByVisualYPosition)中:

在此处更改间距时,间距不起作用,但如果直接在dependency属性中更改间距,则会起作用。此外,这只会更改行号和编辑器的行距,但编辑器“文本”位置不变。我做错什么了吗


我设法创建了一个解决方案并在此处回答了问题:我设法创建了一个解决方案并在此处回答了问题:
    internal void SetTextLines(List<TextLine> textLines)
    {
        this.textLines = textLines.AsReadOnly();
        Height = 0;
        TextView textView = new TextView();

        foreach (TextLine line in textLines)
            Height += (line.Height * textView.LineSpacing);
    }   
    public double GetTextLineVisualYPosition(TextLine textLine, VisualYPosition yPositionMode)
    {
        TextView textView = new TextView();

        if (textLine == null)
            throw new ArgumentNullException("textLine");
        double pos = VisualTop;
        foreach (TextLine tl in TextLines)
        {
            if (tl == textLine)
            {
                switch (yPositionMode)
                {
                    case VisualYPosition.LineTop:
                        return pos;
                    case VisualYPosition.LineMiddle:
                        return pos + (tl.Height * textView.LineSpacing) / 2;
                    case VisualYPosition.LineBottom:
                        return pos + (tl.Height * textView.LineSpacing);
                    case VisualYPosition.TextTop:
                        return pos + tl.Baseline - textView.DefaultBaseline;
                    case VisualYPosition.TextBottom:
                        return pos + tl.Baseline - textView.DefaultBaseline + textView.DefaultLineHeight;
                    case VisualYPosition.TextMiddle:
                        return pos + tl.Baseline - textView.DefaultBaseline + textView.DefaultLineHeight / 2;
                    case VisualYPosition.Baseline:
                        return pos + tl.Baseline;
                    default:
                        throw new ArgumentException("Invalid yPositionMode:" + yPositionMode);
                }
            }
            else
            {
                pos += (tl.Height * textView.LineSpacing);
            }
        }
        throw new ArgumentException("textLine is not a line in this VisualLine");
    }
    public TextLine GetTextLineByVisualYPosition(double visualTop)
    {
        TextView textView = new TextView();

        const double epsilon = 0.0001;
        double pos = this.VisualTop;
        foreach (TextLine tl in TextLines)
        {
            pos += (tl.Height * textView.LineSpacing);
            if (visualTop + epsilon < pos)
                return tl;
        }
        return TextLines[TextLines.Count - 1];
    }
        textEditor.TextArea.TextView.LineSpacing = 3.5f;