WPF TabControl selectionchanged Recurring issues

Source: Internet
Author: User

Very scary question, I used to feel that it was Microsoft's bug.

The problem is this: there is a ComboBox control in the TabItem under my TabControl, and for some reason the TabControl selectionchanged event needs to be performed, but in a more bizarre way, Whenever I select an item in the ComboBox, that is, when the SelectionChanged event of the ComboBox changes, TabControl's SelectionChanged event is executed at the same time, baffled, and later found the relevant reason on the Internet, As follows:

This is because of routedevents.to solve it either handle the selectionchanged of the ComboBox.
In the function handler of the selectionchanged for ComboBox just give E.handled=true;

private void Combobox_selectionchanged (object sender, SelectionChangedEventArgs e)
{
E.handled = true;
}

if u dont want to does this get the OriginalSource property of SelectionChangedEventArgs in the TabControl selectionchanged Handler. This would show whether it is the from TabControl or ComboBox.

It is probably said that Microsoft default events can be passed, if you do not want to pass this, set E. Handled=true terminates the delivery.

Well, the final solution can only be set e.handled=true in the SelectionChanged event of the ComboBox, and not just the ComboBox, but also the Listbox,listview, Controls with SelectionChanged events, such as the DataGrid.

WPF TabControl selectionchanged Recurring issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.