WPF TabControl Control-event-related issues

Source: Internet
Author: User

The content elements of the tabitem of the TabControl control, such as the DataGrid control, need to be concerned about the source of the event when handling the event, and when the event of the DataGrid needs to be processed, the event is passed to TabControl. The way to solve this problem is as follows:

Method One: Determine who triggered this event, according to the source of the event to do the corresponding processing

Private void tabcontrol_selectionchanged (object  sender, SelectionChangedEventArgs e) {       If  is TabControl)     {       //dosomething    }}

Method Two: Register the corresponding event for the DataGrid and other corresponding controls so that it no longer passes upward

Private void datagrid_selectionchanged (object  sender, SelectionChangedEventArgs e) {     True;}

Problem extension: Unable to set the current item dynamically ...

For example, if you want to use the TabItem content element in the DataGrid's double-click event,

void Datagrid_mousedoubleclick (object  sender, MouseButtonEventArgs e)        {     // Do something        }

If you do not add e.handled = true, and at this point we need to dynamically change the selection of TabControl, we will face such a problem, no matter how we change the value below, Its value always changes to the item page when we handle the double-click event.

this. Tabcontrol.selecteditem = Newtabitem;

WPF TabControl Control-event-related 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.