Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am Using following code to change the style for the selected tab

HTML
<pre lang="xml"><Style TargetType="{x:Type TabItem}" x:Key="TabItemStyle">
    <Style.Triggers>
        <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=TabItem}}" Value="True">
            <Setter Property="Background" >
                <Setter.Value>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="LightBlue" Offset="0" />
                        <GradientStop Color="BlanchedAlmond" Offset="1" />
                        <GradientStop Color="#A50000C9" Offset="0.376" />
                        <GradientStop Offset="0.848" />
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="FontSize" Value="18" />
        </DataTrigger>
        <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=TabItem}}" Value="False">
            <Setter Property="Background" >
                <Setter.Value>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="LightGray"  Offset="0" />
                        <GradientStop Color="DarkOrange"  Offset="1" />
                        <GradientStop Color="#A50000C9" Offset="0.376" />
                        <GradientStop Offset="0.848" />
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="FontSize" Value="14" />
        </DataTrigger>
    </Style.Triggers>
</Style>

<Style TargetType="{x:Type TabItem}" BasedOn="{StaticResource  TabItemStyle}"></Style>
but it does not seem to do anything. Please Help....
Posted

1 solution

Hello

Try change the template completely :
http://msdn.microsoft.com/en-us/library/ms754137%28v=vs.110%29.aspx[^]

Regards
Joseph Leung
 
Share this answer
 
Comments
kartikguha 29-May-14 10:20am    
It worked, Thanks :)

But if you could please explain why my previous code didnt worked, it would be very helpfull. Thanks :)
Leung Yat Chun 29-May-14 12:14pm    
Hello kartikguha,

Your code is binding to the DataContext of parent TabItem property, not the TabItem.
I think if you want to bind to the dependency property, you have to use Trigger instead of DataTrigger, e.g.
http://msdn.microsoft.com/en-us/library/ms743015%28v=vs.110%29.aspx

Regards
Joseph Leung

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900