I have a tabbed GUI with each tab containing a Frame. In one of these Frames there is a DataGrid. When the user selects this tab, I need my datagrid sorted, so I'm using the TabControl SelectionChanged event to trigger the sort. However, this event triggers every time an item is selected from the DataGrid, even though the tabs themselves remain untouched.
I've tried number of different events:
GotFocus for a TabItem
RequestBringIntoView for a TabItem
but they all seem to suffer from this problem. What is causing this?
Best Answer
The
TabControl.SelectionChanged
is the same event as aComboBox.SelectionChanged
It originates from
Selector.SelectionChanged
.So, if you do not mark your event as handled in your event handler, it will bubble up the tree, and eventually arrive at your
TabControl
, which is causing this "firing too often" issue.Mark your event as handled in your SelectionChanged of your
ComboBox
/ListBox
/ListView
/any other Selector you use in your DataGrid like so:And this inconvenience will go away ;).