I have one TextBox. On clicking it, all the contents of the TextBox should be selected. What is the solution for this? The code I have tried is:
<TextBox Name="questionTitle_textBox" Text="Question title" PreviewMouseDown="questionTitle_textBox_PreviewMouseDown"/>
The function questionTitle_textBox_PreviewMouseDown
is defined as
private void questionTitle_textBox_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
questionTitle_textBox.SelectAll();
}
This works
and in code behind
You can try to add a trigger to your TextBox
Add
SelectAllAction.cs
to your project:You also need to add two namepsaces to your XAML to use the trigger. The name of my project was WpfApplication1, so you will probably need to change that: