开发者

Trigger in Template in WPF

开发者 https://www.devze.com 2023-03-07 09:57 出处:网络
I\'m creating a Template for TabItem of TabControl. So, I need to create Different background dependent on TabItem.IsSelectedProperty and IsMouseOver as well..

I'm creating a Template for TabItem of TabControl.

So, I need to create Different background dependent on TabItem.IsSelectedProperty and IsMouseOver as well..

So, here is my part of code:

<Window.Resources>
    <Style TargetType="{x:Type TabItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabItem}">
                     <Border BorderBrush="Gray" BorderThickness="1" CornerRadius="6,6,0,0" Margin="-2,0,0,0" Cursor="Hand">
                         <Border.Style>
                             <Style>
                                 <Style.Triggers>
                                     <Trigger Property="TabItem.IsSelected" Value="False">
                                         <Setter Property="Border.Background" Value="ColorIneed"/>
                                     </Trigger>
                                     <Trigger Property="TabItem.IsSelected" Value="True">
                          开发者_StackOverflow中文版               <Setter Property="Border.Background" Value="ColorIneed"/>
                                     </Trigger>
                                     <Trigger Property="Border.IsMouseOver" Value="True">
                                         <Setter Property="Border.Background" Value="ColorIneed"/>
                                     </Trigger>
                                 </Style.Triggers>
                             </Style>
                         </Border.Style>
                     </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>

So, here it is, but it works only on Border.IsMouseOver event...


just have a look at this post.

WPF TabItem Header Styling

0

精彩评论

暂无评论...
验证码 换一张
取 消