First, you need to define AcceptsReturn="True"
in XAML, but I think you know that.
Then, you can use GetLineText
method of TextBox
in such way (I created dummy text box and event handler for purpose of presentation):
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.