Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
612 views
in Technique[技术] by (71.8m points)

event handling - Are Click, Tapped, and PointerPressed synonymous in WinRT-XAML?

Does it matter whether I create event handlers for PointerPressed, Click, or Tapped?IOW, is there any functional difference between the following:

<Button x:Name="BackButton" PointerPressed="BackButton_Click"/>    
<Button x:Name="BackButton" Click="BackButton_Click"/>    
<Button x:Name="BackButton" Tapped="BackButton_Click"/>

?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Click is there for backwards compatibility, and is essentially the same as Tapped. Tapped is a "high level gesture" that will translate automatically to a click, tap, pen press, etc. and is what I would recommend to use.

PointerPressed is not what you want. Here's why: if I press and hold, the PointerPressed event will fire when I initially "press" and then a PointerReleased will fire once it's done. This is more low-level and you can make decisions about how long it was pressed, etc. Typically a long press is NOT what you want to consider a "Click" or a "Tap" because by definition Tap is shorter duration. Therefore, for what you want, "Tap" conveys it best because it translates the gesture for you using the system timing for what is considered a "Tap" vs. a hold and automatically promotes clicks and pen presses to the same event. PointerPressed will fire whenever a button is pressed or a finger is pressed regardless of how long the interaction lasts.

I have a fairly involved app that demonstrates the various interactions that you can download from http://windows8applications.codeplex.com - just refer to the Chapter 4 sample called "Touch."


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...