In Store Apps / Universal Apps / Windows Phone 8.1 Visual Studio 2013 projects, how to to select programmatically all the text in a TextBox with the contextual copy icon menu enabled like in the following screen shot :
(source: free.fr)
The need is to display a text in a context where there is a big probability that the user will want to copy it in the clipboard.
The following tests did not work :
XAML
<TextBox x:Name="MyTextBox" Grid.Row="0"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Text="The text I want to select"
IsReadOnly="True"
IsEnabled="True"
GotFocus="MyTextBox_GotFocus"></TextBox>
<Button x:Name="ButtonSelectAll" Grid.Row="1"
Content="Select All"
HorizontalAlignment="Center"
Click="ButtonSelectAll_Click"></Button>
C#
private void ButtonSelectAll_Click(object sender, RoutedEventArgs e)
{
MyTextBox.SelectAll();
// MyTextBox.Focus(FocusState.Programmatic);
}
private void MyTextBox_GotFocus(object sender, RoutedEventArgs e)
{
MyTextBox.SelectAll();
}
The try on Click event do nothing. The try on GotFocus event select all the text but the contextual copy icon menu and the two handles are not shown. If you add on the Click method "text.Focus(FocusState.Programmatic);" then the text is selected but the copy icon is not shown. And unfortunately, if you touch this text with you finger with the intention that the "copy icon" will appear, you lose the selection.
@efdummy Try this: