La rimozione di IsEnabled e l'impostazione di TextBox come ReadOnly consentirebbero di selezionare il testo ma interrompere l'immissione dell'utente.
IsReadOnly="True"
L'unico problema con questo approccio è che, anche se non sarà in grado di digitare nel controllo TextBox sarà ancora guardare 'Abilitato'.
Per risolvere il problema (se si desidera?) È possibile aggiungere uno stile per schiarire il testo e scurire lo sfondo (per renderlo disattivato).
Ho aggiunto il seguente esempio con uno stile che farà scorrere la casella di testo tra un aspetto disattivato e abilitato.
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<Trigger Property="IsReadOnly" Value="True">
<Setter Property="Background" Value="LightGray" />
</Trigger>
<Trigger Property="IsReadOnly" Value="True">
<Setter Property="Foreground" Value="DarkGray" />
</Trigger>
<Trigger Property="IsReadOnly" Value="False">
<Setter Property="Background" Value="White" />
</Trigger>
<Trigger Property="IsReadOnly" Value="False">
<Setter Property="Foreground" Value="Black" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<TextBox Height="23" Margin="25,22,133,0" IsReadOnly="True" Text="monkey" Name="textBox1" VerticalAlignment="Top" />
<Button Height="23" Margin="25,51,133,0" Name="button1" VerticalAlignment="Top" Click="button1_Click">Button</Button>
</Grid>
private void button1_Click(object sender, RoutedEventArgs e)
{
textBox1.IsReadOnly = !textBox1.IsReadOnly;
}
fonte
2009-07-27 07:22:01
Ho usato 'SelectAll()' e quindi consente di fare clic con il tasto destro del mouse e copiare il contenuto. – EricG