TabChanged event of TabControl in WPF

AndreyAkinshin picture AndreyAkinshin · Nov 17, 2011 · Viewed 29.2k times · Source

I have a TabControl in WPF. I want to find an event that occurs when changing tabs. What is the name of this event?

Answer

myermian picture myermian · Nov 17, 2011

The TabControl inherits from a Selector which contains the SelectionChanged event.

<TabControl SelectionChanged="OnSelectionChanged" ... />

private void OnSelectionChanged(Object sender, SelectionChangedEventArgs args)
{
    var tc = sender as TabControl; //The sender is a type of TabControl...

    if (tc != null)
    {
        var item = tc.SelectedItem;

        //Do Stuff ...
    }
}