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 ~