开发者

WPF TabControl - getting notification of a particular tabitem being opened?

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开发者_JAVA百科 but I can't find anything like this.

Can anyone point me in the right direction?

Thanks in advance!


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;
    //}
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜