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.

1 Answer 1

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... } } 
Sign up to request clarification or add additional context in comments.

1 Comment

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? :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.