XAML RichEditBox lines count
本文关键字:count lines RichEditBox XAML | 更新日期: 2023-09-27 18:34:35
UWP Windows 10.
如何获取RichEditBox的行数?
我想将行数、当前行和当前行绑定到状态栏中的标签(如记事本(。我该怎么做?
看看这个扩展类
public class TextBoxEx : TextBox
{
public TextBoxEx()
{ }
public void GoTo(int line, int column)
{
if (line < 1 || column < 1 || this.Lines.Length < line)
return;
this.SelectionStart = this.GetFirstCharIndexFromLine(line - 1) + column - 1;
this.SelectionLength = 0;
}
public int CurrentColumn
{
get { return this.SelectionStart - this.GetFirstCharIndexOfCurrentLine() + 1; }
}
public int CurrentLine
{
get { return this.GetLineFromCharIndex(this.SelectionStart) + 1; }
}
}
甚至更好;你可以这样写:
public int CurrentColumn
{
get { return textBox1.SelectionStart - textBox1.GetFirstCharIndexOfCurrentLine() + 1; }
}