Esempio:
xaml
codice:
<Grid>
<TextBox Height="23" HorizontalAlignment="Left" Margin="24,21,0,0" Name="textBox1" VerticalAlignment="Top" Width="208" />
<Button Content="Metodo1" Height="23" HorizontalAlignment="Left" Margin="24,58,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
<Button Content="Metodo2" Height="23" HorizontalAlignment="Left" Margin="113,58,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />
</Grid>
code-behind
codice:
private void button1_Click(object sender, RoutedEventArgs e)
{
textBox1.Text = "Testo da selezionare";
textBox1.SelectionStart = 0;
textBox1.SelectionLength = textBox1.Text.Length;
textBox1.Focus();
}
private void button2_Click(object sender, RoutedEventArgs e)
{
textBox1.SelectedText = "Testo da selezionare";
textBox1.Focus();
}
Ciao