
Silverlight for Windows Phone allows you to process touch input by using manipulation events. By using these events, you can move and scale objects in response to touch and multitouch input. Manipulation events are supported on objects derived from UIElement.
Note: |
|---|
Rotate transforms are not supported on Windows Phone 7 Series. |
Manipulation events are supported by default on Windows Phone, so the IsManipulationEnabled property is not supported.
The following manipulation events are supported:
Note: |
|---|
Inertia events are not supported in this release of Silverlight for Windows Phone. |
To create an application
Create a new Windows Phone project in Visual C# or Visual Basic.
Add the following XAML to MainPage.xaml.
This markup creates a simple application that contains a blue rectangle on a Canvas. The application subscribes to the ManipulationDelta event. These events contain the logic to move the Rectangle when the user manipulates it.
In the PhoneApplicationPage class, add the following variables.
In the PhoneApplicationPage class, add the following stub for the ManipulationDelta event handler.
In the PhoneApplicationPage class constructor, add event listeners for ManipulationDelta.
Add the following code to the class constructor.
In the PhoneApplicationPage class, add the following code to the ManipulationDelta event handler.
The ManipulationDelta event occurs when the touch input changes position and can occur multiple times during a manipulation. The event can also occur after the user's finger is raised. For example, if the user drags a finger across a screen, the ManipulationDelta event occurs multiple times as the finger moves.
The code applies the DeltaManipulation to the RenderTransform of the Rectangle to move it as the user moves the touch input.
Note:The Windows Phone Emulator does not support multitouch input through the mouse, so you must test scale transforms on a development computer that supports touch input, or test on an actual device.
void PhoneApplicationPage_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) { // Scale the rectangle. if (e.DeltaManipulation.Scale.X != 0) { this.scale.ScaleX *= e.DeltaManipulation.Scale.X; } if (e.DeltaManipulation.Scale.Y != 0) { this.scale.ScaleY *= e.DeltaManipulation.Scale.Y; } // Move the rectangle. this.translation.X += e.DeltaManipulation.Translation.X; this.translation.Y += e.DeltaManipulation.Translation.Y; }Build and run the project.
You should see a blue square appear in the window.
