【发布时间】:2020-05-09 08:17:37
【问题描述】:
【问题讨论】:
-
这能回答你的问题吗? C# XML Editor - Matching XMLNode
-
他好像在问同样的问题,但没有“答案”。
【问题讨论】:
首先,您需要在 XAML 中定义 AcceptsReturn="True",但我想您知道这一点。
然后,您可以这样使用TextBox 的GetLineText 方法(我创建了虚拟文本框和事件处理程序用于演示):
private void txb_KeyDown(object sender, KeyEventArgs e)
{
// Handle event only if Q is pressed.
if (e.Key != Key.Q) return;
// Count how many newline characters there were, to determine index of current line.
var lineIndex = txb.Text.Substring(0, txb.CaretIndex).Count(ch => ch == '\n');
// Get current line.
var currentLine = txb.GetLineText(lineIndex);
}
【讨论】: