Search code examples
c#.netwpftabcontroltabitem

TabControl Saving on selected tab item changed


I need to save data in distinct TabItem every time when user switches to another tabitem.

I try to operate TabControl.SelectionChanged event, but there is no info about previously selected tab item.

So, how to get moment when user switches from my TabItem to another?


Solution

  • You can make a global variable to store what is the last tab

    private TabPage LastTab = null;
    
    private void tabSelectionChanged(...)
    {
      if(LastTab != null)
         //Do save
    
      LastTab = tab.SelectedTabPage;// or equivalent 
    }