PointerPressed 在左键单击时不起作用 [英] PointerPressed not working on left click

查看:21
本文介绍了PointerPressed 在左键单击时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 WPF+C# 上为 Windows 8 创建 Metro (Microsoft UI) 应用程序时,我遇到了按钮上的 PointerPressed 事件的困难.当我执行左键单击(通过鼠标)时不会发生事件,但它会在右键单击或点击的情况下发生.那么这个事件有什么问题呢?例如

Creating Metro (Microsoft UI) app for Windows 8 on WPF+C#, I met difficulty with PointerPressed event on a button. Event doesn't happen when i perform left-click (by mouse), but it happens in case with right-click or tap. So what's wrong with that event? for example

 <Button x:Name="Somebutton"  Width="100" Height="100"
PointerPressed="Somebutton_PointerPressed"/>

推荐答案

解决方案非常简单:这些事件必须通过 AddHandler 方法而不是通过 XAML 来处理.

The solution is pretty simple: these events have to be handled not through XAML but thorugh AddHandler method.

SomeButton.AddHandler(PointerPressedEvent, 
new PointerEventHandler(SomeButton_PointerPressed), true); 

这篇关于PointerPressed 在左键单击时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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