WPF Tab Control: How do I get the currently selected tab?

Bob picture Bob · Nov 23, 2010 · Viewed 58.5k times · Source

In my tab SelectionChanged event (is this the correct event, I can't find a tab changed event?), how do I access the new tab?

Also from outside this event in normal code, how do I access the currently selected tab?

  TabControl.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(TabControl_SelectionChanged);

  void TabControl_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
  {
      //How so access my currently selected tab???
  }

Answer

MarcelDevG picture MarcelDevG · Nov 23, 2010

TabControl.SelectedItem is the selected tab.

cast it to a TabItem to get the properties.

What I mostly do is bind it to a viewmodel.