且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

TabControl 的 SelectionChanged 事件问题

更新时间:2023-12-06 17:07:10

我觉得我需要休息一下,因为我的问题真的很傻:

I think I need to take a rest, since my problem is really silly:

事实证明,我应该使用 TabItem 而不是 TabControl,因为它是我感兴趣的控件.

Turns out that instead of TabControl I should have used TabItem since it is the control I am interesting in.

所以,我的代码必须如下:

So, my code has to be as below:

 void mainTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (e.Source is TabItem)
        {       
            if (this.IsLoaded)
            {
                //do work when tab is changed
            }
        }
    }