WPF文本框AcceptsReturn=True

WPF文本框AcceptsReturn=True,wpf,vb.net,textbox,Wpf,Vb.net,Textbox,在WPF应用程序中,我有一个文本框 我将其AcceptsReturn属性设置为true。 因此,我可以在多行中输入数据 当用户在文本框中按enter键时,我要检查: 1) Is the cursor on the last line? 2) If cursor is on the last line then check if thatLine.Text = Nothing? 像这样的 private void TextBoxOnTextChanged(object sender, TextC

在WPF应用程序中,我有一个文本框

我将其
AcceptsReturn
属性设置为
true
。 因此,我可以在多行中输入数据

当用户在文本框中按enter键时,我要检查:

1) Is the cursor on the last line?
2) If cursor is on the last line then check if thatLine.Text = Nothing?
像这样的

private void TextBoxOnTextChanged(object sender, TextChangedEventArgs e)
  {
     TextBox tb = sender as TextBox;
     if (tb == null)
     {
        return;
     }

     string[] lines = tb.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
     if (tb.CaretIndex >= tb.Text.Length - lines.Last().Length)
     {
        // cursor is on last line

        if (string.IsNullOrEmpty(lines.Last()))
        {
           // cursor is on last line and line is empty
        }
     }
  }
ok是c语言,但我不知道vb语法


如果需要翻译成vb:;-)

我用显式类型更改了示例代码。希望这对汉克斯有帮助。它起作用了。我使用代码转换器将new[]更改为new(),然后添加了新字符串()。现在它起作用了。