我试过下面的代码以在聚焦时选择文本框中的所有文本。但这是行不通的。
XAML:
<TextBox Text="test1" Width="100" Height="200"
GotFocus="TextBox_GotFocus"></TextBox>
Run Code Online (Sandbox Code Playgroud)
C#:
private void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
(sender as TextBox).SelectAll();
//(sender as TextBox).Select(0, (sender as TextBox).Text.Length);
(sender as TextBox).Focus();
e.Handled = true;
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过异步。冲浪很多,但是没有用。请提出建议?