In WinRT XAML - tapping and clicking on a button is not the same?

时光怂恿深爱的人放手 提交于 2019-12-11 12:58:00

问题


When hooking the Tapped event on a page (so I can get all events that are not caught by children), I am also getting the event fired when a user taps a button on the page.

I would have expected the button to "swallow" the tap, but that does not seem to be the case.

The workaround is simple, if annoying - hook the Tap event on each button present and set Handled to true. I get how to do the workaround.

My question is whether or not I am understanding this correctly. If hooking the Tap event on all my buttons that are on the page (so I don't get the tap event on the page fired) really the correct way to do this.

Thanks.


回答1:


You should handle the Click event on the button, not the Tapped event. If the Tapped event still bubbles to the page - yes, by all means, handle it on the button and mark it Handled to prevent bubbling or try to change the IsTapEnabled value on the button. If handling the event is the only way and you don't like the code behind - you can either have all button Tapped events use the same handler or define an attached behavior that does the swallowing in a separate class where you define the behavior.



来源:https://stackoverflow.com/questions/22542972/in-winrt-xaml-tapping-and-clicking-on-a-button-is-not-the-same

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!