Best_Where_Gives
Best_Where_Gives

Reputation: 481

wpf tabcontrol: Change content of generic tab based on selected tab

MainWindow.xaml:

<TabControl TabStripPlacement="Left">
  <tabs:tab1/>
  <tabs:tab2/>
</TabControl>

tab1.xaml:

<usercontrol:GenericTab >
</usercontrol:GenericTab>

GenericTab.xaml:

<Button Name="btn_Button" Content="{Binding ButtonText, Mode=OneWay }" Command="{Binding ClickCommand}" ></Button>

How to achieve following behavior: If tab1 is selected in MainWindow, GenericTab.Button-Content should be for example "hello tab1" and if tab2 is selected, Generictab.Button-Content should be "hello tab2" ?

Upvotes: 0

Views: 899

Answers (1)

mm8
mm8

Reputation: 169150

You could set the Tag property of the TabItem and then bind the Button's Content property to this one.

MainWindow.xaml:

<TabControl TabStripPlacement="Left">
    <TabItem Header="Tab1" Tag="hello tab1">
        <usercontrol:GenericTab />
    </TabItem>
    <TabItem Header="Tab2" Tag="hello tab2">
        <usercontrol:GenericTab />
    </TabItem>
</TabControl>

GenericTab.xaml:

<Button Name="btn_Button" Content="{Binding Path=Tag, RelativeSource={RelativeSource AncestorType=TabItem}}" Command="{Binding ClickCommand}" ></Button>

Upvotes: 1

Related Questions