Allow Pointer events to bubble from Button clicks

2019-08-23 02:09发布

问题:

What steps to I need to take to enable Pointer events such as PointerPressed and PointerMoved to fire on a Container element when Buttons inside the container are clicked?

回答1:

The approach I ended up taking was to add event handlers to the container, and set the bool handledEventsToo parameter to true.

mainPage.AddHandler(PointerPressedEvent, new PointerEventHandler(pointerPressedHandler), true);
mainPage.AddHandler(PointerMovedEvent, new PointerEventHandler(pointerMovedHandler), true);

This means the container still gets a chance to process the events even if they have already been handled.



回答2:

Create a custom button control. Grab the template of a regular button and handle the events yourself - then you will be able to route it.