TabItem Style Trigger Problem


I'm developing a WPF application which makes extensive use of the TabControl.  Part of the requirement is to style individual TabItem background colours, for example TabItem1 = Red, TabItem2 = Green etc etc, I'm using Styles and Templates to achieve this which is working nicely.  The problem I have is that when a tab IsSelected I must also change the background colour for the TabControl, ideally I would like to use a Trigger in the TabItem template to set the background colour for the TabControl using all xaml if possible? not sure if it your able to access a TabControl property within a TabItem template?

Being my first WPF application I would certainly appreciate any ideas, comments etc.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I'm assuming that what you're looking for is for the TabControl to always have the same Background as its selected TabItem. The easiest way to do that is going to be to simply bind the two together, as in the attached code. If this isn't what you were looking for, please describe it in more detail. Hope this helps!
<Window x:Class="WpfApplication1.Window1"
    Title="Window1" Height="300" Width="300">
        <Style TargetType="TabControl" x:Key="SelectedBackgroundStyle">
            <Setter Property="Background"
                    Value="{Binding SelectedItem.Background, RelativeSource={x:Static RelativeSource.Self}}">
        <TabControl x:Name="Tabs" Style="{StaticResource SelectedBackgroundStyle}">
            <TabItem Header="First" Background="Blue">
            <TabItem Header="Second" Background="Green"/>
            <TabItem Header="Third"  Background="Orange"/>

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DotNetRulesAuthor Commented:
Perfect! thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.