Reputation: 101
When a TextBox is in readonly and on tabbing i want to disable the focus border of the textbox, i wanted to do this in Style of textbox.Can any one help me to achieve this?
Updated the content:
Screenshot:
Upvotes: 0
Views: 1379
Reputation: 629
Place a condition like the below in your textbox style
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsReadOnly" Value="True"></Condition>
<Condition Property="IsFocused" Value="True"></Condition> </MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter Property="BorderBrush" Value="{#7B2F81}"></Setter>
</MultiTrigger.Setters>
Upvotes: 1
Reputation: 22702
Try this:
<Window.Resources>
<Style x:Key="FocusVisualStyle" TargetType="{x:Type Control}">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Control}">
<Border SnapsToDevicePixels="True"
CornerRadius="0"
BorderThickness="2"
BorderBrush="#7B2F81" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="Pink" />
<Style.Triggers>
<Trigger Property="IsReadOnly" Value="True">
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisualStyle}" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<TextBox Text="TestText"
IsReadOnly="True"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
If TextBox.IsReadOnly == True
then set FocusVisualStyle
in StyleTrigger. Visual behavior of Focus you can customize in FocusVisualStyle
.
Upvotes: 0