在 WinRT XAML 中 - 点击和单击按钮不一样? [英] In WinRT XAML - tapping and clicking on a button is not the same?

查看:19
本文介绍了在 WinRT XAML 中 - 点击和单击按钮不一样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在页面上挂接 Tapped 事件时(这样我就可以获取所有未被儿童捕获的事件),当用户点击页面上的按钮时,我也会触发该事件.

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.

解决方法很简单,但很烦人 - 在每个按钮上钩住 Tap 事件并将 Handled 设置为 true.我知道如何解决这个问题.

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.

我的问题是我是否正确理解了这一点.如果在页面上的所有按钮上挂钩 Tap 事件(这样我就不会触发页面上的 tap 事件)真的是正确的方法.

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.

谢谢.

推荐答案

您应该处理按钮上的 Click 事件,而不是 Tapped 事件.如果 Tapped 事件仍然冒泡到页面 - 是的,无论如何,在按钮上处理它并将其标记为 Handled 以防止冒泡或尝试更改 按钮上的 IsTapEnabled 值.如果处理事件是唯一的方法并且您不喜欢背后的代码 - 您可以让所有按钮 Tapped 事件使用相同的处理程序,或者定义一个附加的行为,在单独的类中进行吞咽定义行为的地方.

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.

这篇关于在 WinRT XAML 中 - 点击和单击按钮不一样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆