Reputation: 481
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
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