[英]Select all in TextBox by clicking a button
I would like to highlight all content of a TextBox
by a press of a button, but it doesn't work. 我想通过按一个按钮来突出显示
TextBox
的所有内容,但是它不起作用。
private void selectAll_Click(object sender, RoutedEventArgs e)
{
myTextBox.SelectAll();
}
I tried this as well: 我也尝试过这个:
myTextBox.SelectionStart = 0;
myTextBox.SelectionLength = myTextBox.Text.Length;
Not working. 不工作 The properties seem to change, but the highlight is not present on the UI.
这些属性似乎已更改,但突出显示未出现在UI上。 If I select the text manually, the highlight works correctly.
如果我手动选择文本,则突出显示将正常工作。
What should I do? 我该怎么办?
添加它,您将看到UI刷新:
myTextBox.Focus();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.