Silverlight for Windows Phone 7 is version 3.7 hence a WP7 control should be easily used within a standard Silverlight 4 application. But that’s in theory. The major differences between these two worlds are the so called “Manipulation” events. Each UIElement in WP7’s Silverlight is “enabled” with the following routed events:
Generally this sequence of events encapsulates one or more touch gestures in a transaction block. The event arguments carry all the information needed to determine what the gesture is and what effect to generate. And of course RadControl for WP7 use these events extensively in order to provide consistent and rich user experience throughout the entire framework.
But what about running these controls in a standard Silverlight Application where the manipulation events are not present? The solution is to generate the gestures manually, depending on mouse input – meet the ManipulationBehavior class we have created to enable standard single-touch gestures outside the WP7 context. The behavior itself attaches to a valid UIElement instance and hooks its MouseLeftButtonDown, MouseMove, MouseLeftButtonUp and MouseLeave events. When mouse input is received, the behavior generates the appropriate gestures and raises one or more of the following events:
In order to determine whether a flick gesture should be generated we calculate the timespan between the last mouse move and the MouseLeftButtonUp event:
And here is how the velocity is calculated:
Well, enough words, you’d better see it for yourself (this is not just a picture :)
Please note that the text here looks a bit different than in WP7 because the Segoe WP Font is installed with the Windows Phone 7 tools and we have intentionally specified the standard Segoe UI Font for the demo.
Georgi has 15 years of experience in multiple software technologies. Ten years ago, he joined Telerik, later acquired by Progress, and he has set up and led multiple products and teams since. His latest endeavor is building a product that adds the Progress value into the augmented and virtual reality development workflow.
Subscribe to be the first to get our expert-written articles and tutorials for developers!