I want to disable the selection of text in a textbox using a style preferably. The reason is that I have a style that makes a textbox look like a textblock until a certain criteria (IsRenaming) is met. These are the nodes of a treeview so I don't want the user to be able to select the text. Here is the style:
<Style x:Key="TextBlockStyleForTextBox" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="IsReadOnly" Value="True" />
</Style>
<Style x:Key="RenamingTextBox" TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextBlockStyleForTextBox}">
<Setter Property="Cursor" Value="Arrow"/>
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="0" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsRenaming}" Value="true">
<DataTrigger.Setters>
<Setter Property="TextBox.IsReadOnly" Value="False" />
<Setter Property="Cursor" Value="IBeam" />
<Setter Property="Background" >
<Setter.Value>
<SolidColorBrush Color="{DynamicResource WhiteColor}"/>
</Setter.Value>
</Setter>
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Padding" Value="2" />
<Setter Property="FocusManager.FocusedElement" Value="{Binding RelativeSource={RelativeSource Self}}"/>
<Setter Property="behaviors:TextBoxBehavior.SelectAll" Value="True"/>
</DataTrigger.Setters>
</DataTrigger>
</Style.Triggers>
</Style>
I don't think I am overriding the IsReadOnly anywhere. Here is my textbox definition:
<DataTemplate x:Key="MyTemplate" >
<TextBox Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType=TreeView}}"
Style="{StaticResource RenamingTextBox}">
... etc