1
votes

I'm using WPF 4 I have a TabControl that contains a bunch TabItems. I want to be notfied when one tab in particular is opened/selected. I wrongly assumed that there would be something like "OnTabItemChanged" type event but I can't find anything like this.

Can anyone point me in the right direction?

Thanks in advance!

1

1 Answers

3
votes

You have the SelectionChanged event on the TabControl

Example of usage

Xaml

<TabControl ...
            SelectionChanged="tabControl_SelectionChanged">

Code behind

private void tabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    TabControl tabControl = sender as TabControl;
    TabItem tabItem = tabControl.SelectedItem as TabItem;
    //...

    // Or...
    //if (e.AddedItems.Count > 0)
    //{
    //    TabItem selectedTabItem = e.AddedItems[0] as TabItem;
    //}
}