CogentP
CogentP

Reputation: 259

WPF TabControl Proprty Binding with Child Elements

I have a WPF 4.0 TabControl that has three TabItems (aka Children). Basically each Child has a color, in other words each Tab will have a color.

I want to bind the background of TabControl to the currently selected TabItem. So if * I select Apples and its background is red, i want the TabControl's background to be Red. When * I select to Grapes and its background is purple, I want the TabControl's background to be Purple.

I know it has something to do with element binding, but all options I found where specifically towards one specific TabItem, and not generic. How can I do this?

Upvotes: 1

Views: 386

Answers (1)

Fede
Fede

Reputation: 44048

<TabControl Background="{Binding SelectedItem.Background, RelativeSource={RelativeSource Self}}">
    <TabItem Background="Red" Header="Red"/>
    <TabItem Background="Green" Header="Green"/>
    <TabItem Background="Blue" Header="Blue"/>
</TabControl>

Upvotes: 3

Related Questions