Reputation: 5935
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.
Upvotes: 1
Views: 2470
Reputation: 93561
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...
}
}
Upvotes: 2