This question was recently answered in a private support case, and I thought I'd share it here in the forums:
Q: When using a XamComboEditor in a XamTabControl, why does the XamTabControl’s SelectionChanged event fire when an item in the XamComboEditor is selected?
A: This is caused by the internal use of ComboBox in the XamComboEditor. Both XamComboEditor and XamTabControl derive from ItemsControl. When the ComboBox inside XamComboEditor raises its SelectionChanged event (which is actually ItemsControl.SelectionChanged) it gets bubbled up to the XamTabControl.
You can prevent this from happening by hooking into the ItemsControl.SelectionChanged on the XamComboEditor and marking that event handled to prevent it from bubbling up. Otherwise, you can simply check if the sender object in the event handler is the one you are expecting before executing your logic.
Currently using WPF 12.1 with XamComboEditor on a XamTabControl and experiencing this issue. I've handled the event in the SelectedItem Changed event on the XamComboEditor, as so:
private void xamComboEditorReferenceLocation_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
e.Handled = true;
}
but I still have the problem.
Any ideas?
The xamComboEditor is not a Selector. Selector defines a routed bubble event named SelectionChanged. Since controls like ComboBox and TabControl derive from Selector they will each raise this event and it will bubble up the visual/logical tree if it is not handled. The easiest thing to do is to check the e.OriginalSource and make sure it is for the control that you want to respond to - e.g. if you're trying to listen if this is the tabcontrol's SelectionChanged then check to make sure e.OriginalSource is that tab control (e.g. sender == e.OriginalSource). If you want handle the SelectionChanged of the descendant elements - like the MS ComboBox that is within the template of the xamComboEditor - then you have to handle the SelectionChanged event of those descendant Selector derived classes. It is the SelectionChanged of that ComboBox control and not the SelectedItemChanged of the xamComboEditor that must be handled in this case. Since this is a routed bubble event you can use the AddHandler method of the xamComboEditor (or any element in the path) and pass in the Selector.SelectionChangedEvent as the RoutedEvent and the appropriate delegate.