Todd Main
Todd Main

Reputation: 29153

MouseLeftButtonUp/Down versus ManipulationCompleted

Is there any reason why either MouseLeftButtonUp (or Down) would be chosen over ManipulationCompleted for a given control that is really just needs a "click" event handled (i.e. user taps a control and something happens) in Windows Phone 7?

I know ManipulationCompleted is all fancy and more can be done with it, like detecting a swipe, but all I'm asking about is what would be considered a "Click" - i.e. is one better than the other and if so, why?

Upvotes: 0

Views: 1224

Answers (3)

Matt Lacey
Matt Lacey

Reputation: 65556

If just wanting to handle the user selecting something by touching it, you can get a better user experience by using the Tap gesture in the Silverlight Toolkit.

If you don't use this then you have to handle 2 extra events for each item you want to touch. As you need to handle the Up & Down versions of the LeftMouseButton* events or the ManipulationStart & Completed to make sure that the item being touched when the finger is removed is the same one that was first touched when the finger made contact wiht the device. If you don't do this you can get weird behaviour where the item selected is not necessarily the one most users would expect.

Upvotes: 0

Den
Den

Reputation: 16826

It really depends on what kind of information you need to receive and process when the user touches a control. MouseLeftButtonUp / MouseLeftButtonDown are the very basic touch processing events - these offer an easy way to track down the relative touch position, so if you need to know how "far" from another control a click happened, you can use something like this:

Debug.WriteLine(e.GetPosition(button1).X);

Where e represents MouseButtonEventArgs.

ManipulationCompleted, on the other hand, is more appropriate for cases where you need to:

  • Move the control
  • Resize the control
  • Perform any transformations on the control

When ManipulationCompleted is invoked, your application receives way more information than needed (since you are only processing a simple touch), so I would not recommend it for very simple tasks.

Also, remember that for Button-based controls there is ClickMode where you explicitly declare when to consider a click. That's where MouseLeftButtonUp and MouseLeftButtonDown play an important role as you can tie specific actions when the button is in different states. This is not possible with ManipulationCompleted, that will be fired no matter what state the button is in.

Upvotes: 2

Lukasz Madon
Lukasz Madon

Reputation: 14994

This one is confiusing. Why MouseLeftButtonUp works in WP7? There is no mice! (Prolly, they wanted to make apps easer to move to SL and vice versa)

When developing Siliverlight for Windows Phone app, it is better to use ManipulationCompleted. It it less confusing.

PS. I also don't like FindResource. I bet is a dictionary behind the scenes, hence should be GetResource. Find indicates that it takes O(lg(n)) or more to get the resource.

Upvotes: 0

Related Questions