开发者

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

开发者 https://www.devze.com 2023-02-06 16:51 出处:网络
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'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

精彩评论

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

关注公众号