1

I'm using tab control and I want to handle tabchanged event.

I was trying to use SelectionChanged event with no luck. It's being fired too many times (after loading tabcontrol, or adding new tab). I would like to handle this event only when user navigates between tabs.

I have found solution for WPF (Is there Selected Tab Changed Event in the standard WPF Tab Control) but it's no good for Silverlight. TIA.

Community
  • 1
  • 1
Jarek
  • 5,885
  • 6
  • 41
  • 55

1 Answers1

2

Firing "too many times" should not be a problem if you check for an actual change to the SelectedIndex property in the event.

private int LastSelectedTab = -1;

void tab_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    TabControl tab = sender as TabControl;
    if (this.LastSelectedTab != tab.SelectedIndex)
    {
        this.LastSelectedTab = tab.SelectedIndex;
        // Now do your thing...
    }
}
iCollect.it Ltd
  • 92,391
  • 25
  • 181
  • 202
  • 2
    If you want a generic fix subclass TabControl and implement your own event that only gets called by the above code in that class... `SelectionActuallyChangedByAHuman`? :) – iCollect.it Ltd Sep 09 '11 at 13:03