简体   繁体   中英

How can I change tab border brush on changing key board focus in wpf style

I want to change border color of tab item when it has key board focus. I have written following trigger in its style

<Style TargetType="{x:Type TabItem}" x:Key="{x:Type TabItem}">
 <Style.Triggers>
        <Trigger Property="IsKeyboardFocused" Value="True">
            <Setter Property="BorderBrush" Value="#800000" />
        </Trigger>

It works fine for all other UI controls except tab itme. Can any one please help

Although this is working fine for me (make sure you actually have the keyboard focus to view the change in color)

 <Style TargetType="{x:Type TabItem}" >
            <Style.Triggers>
                <Trigger Property="IsKeyboardFocused" Value="True">
                    <Setter Property="BorderBrush" Value="Yellow"/>
                </Trigger>

                <Trigger Property="IsKeyboardFocused" Value="False">
                    <Setter Property="BorderBrush" Value="Blue"/>
                </Trigger>
            </Style.Triggers>
        </Style>

You can also try this to change the color if any item inside the Tab have keyboard focus

 <Style TargetType="{x:Type TabItem}" >
            <Style.Triggers>
                <Trigger Property="IsKeyboardFocusWithin" Value="True">

                    <Setter Property="BorderBrush" Value="Yellow"/>
                </Trigger>
                <Trigger Property="IsKeyboardFocusWithin" Value="False">

                    <Setter Property="BorderBrush" Value="Blue"/>
                </Trigger>
            </Style.Triggers>
        </Style>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM