PointerPressed not working on left click(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 在左键单击时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PointerPressed 在左键单击时不起作用


基础教程推荐
- 如何激活MC67中的红灯 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01