79511717

Date: 2025-03-15 20:21:59
Score: 1
Natty:
Report link

15 Years later....

Using solutions mentioned by other here (Thanks!) , I ended up using the following code.
I need events to fire only when a tab is clicked.

I have DataGrids in Tabs and selecting any Row would fire the TabControl.SelectionChanged event.

Using this in the TabControl_SelectionChanged event solved my problem.

I added the option to switch by TabItem.Name instead of its SelectedIndex in case I move tabs around in development later.

if (e.OriginalSource is TabControl)
 {
     var tabControl = e.OriginalSource as TabControl;

     if (tabControl.Name == "<YourTabControlName>")
     {
         switch ((tabControl.SelectedItem as TabItem).Name)
         {
             case "First_Tab": //First Tabs Name
                     //DOWORK
                 break;
             case "Second_Tab": //Second Tabs Name
                 //DOWORK
                 break;    
             default:
                 break;
         }
     }
 }
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (0.5): I need
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: SiRaDuDe