WPF capture event even if this event is marked as handled

Source: Internet
Author: User

Previous blog posts:WPF drag SummaryIn debuglzq, the problem is: debuglzq registers a mouseleftbutton event for all the UI controls in the container. The button control cannot capture the event. Add a breakpoint to check it,ProgramThis location is not reached at all. At that time, I just gave a brief introduction and thought it was not enough. Therefore, I decided to send another blog post to discuss it.

 
Foreach(Uielement uieleInLayoutroot. Children ){Uiele. mousemove + =NewMouseeventhandler (element_mousemove); uiele. mouseleftbuttondown+ =NewMousebuttoneventhandler (element_mouseleftbuttondown); uiele. mouseleftbuttonup+ =NewMousebuttoneventhandler (element_mouseleftbuttonup );}

Some people say that the clickedmode of the button control is hover, and debuglzq has tried a lot of problems.

There are other similar problems. If I want to drag the Textbox Control, the mouseleftbuttondown event still cannot be triggered.

In more scenarios, my program has a third-party control. I need to capture a routing event of this control, however, this event is marked as handled = true in event processing of this third-party control. How can we do this?

The following is a solution to the problem:CodeFragment:

 
If(UieleIsButton | uieleIsTextbox) {uiele. addhandler (button. mouseleftbuttondownevent,NewMousebuttoneventhandler (element_mouseleftbuttondown ),True);}

The key point of this Code is the last one.TrueIt tells the WPF engine call this handle even if it is marked as handled = true.
It can be seen that after the WPF routing event is marked as handled, it is not passed on the visual tree; instead, it does not call the handler.

hope to help you ~

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.