user2408987
user2408987

Reputation: 101

Disable focus on tabstop when TextBox is readonly

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: enter image description here

Upvotes: 0

Views: 1379

Answers (2)

Arushi Agrawal
Arushi Agrawal

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

Anatoliy Nikolaev
Anatoliy Nikolaev

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

Related Questions