本文介绍了我可以获得按钮的PointerPressed事件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将一个PointerPressed事件附加到我的一个按钮上,但是我看到事件被触发的唯一一次是按下鼠标右键。  按鼠标左键无效。  是否无法为Button类控件获取这些事件?

I have attached a PointerPressed event to one of my buttons, but the only time I see the event fired is if I press the right mouse button.  Pressing the left mouse button has no effect.  Is it not possible to get these events for Button class controls?

谢谢。

推荐答案

 按钮控件      ; PointerPressed事件内部实现其悬停/点击行为并将PointerPressed路由事件标记为已处理 - 这意味着默认情况下事件不会冒泡到您的处理程序。

The Button control handles the PointerPressed event internally to implement its hover/click behavior and marks the PointerPressed routed event as handled - this means the event will not be bubbled up to your handler by default.

有一个概述此处的路由事件模型及其与控件的交互,在"控件中的输入事件处理程序"下:

There's an overview of the routed events model and its interaction with controls here, under the "Input Event Handlers in Controls":

http://msdn.microsoft.com/en-us/library/cc189018(v = VS.95).aspx

(这文档 是  for Silverlight,但概念是相同的)

(this documentation is for Silverlight, but the concept is the same)

如果您确实需要PointerPressed事件,有些特殊原因可以使用

AddHandler
方法即使添加处理程序路由事件通常不会被提升,但对此的需求应该很少。 通常,对于用户交互,您应始终使用Click。

If you really need the PointerPressed event for some special reason you can use theAddHandler method to add a handler even though the routed event doesn't normally get raised, but the need for this should be rare.  In general for user interaction you should always use Click.


这篇关于我可以获得按钮的PointerPressed事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 20:52
查看更多