Silverlight 3 Quick Tip: Multitouch support on Windows 7
Silverlight 3 supports Multitouch on Windows 7.
Touch class –provides input information and resides in System.Windows.Input namespace
“FrameReported” event - fired when touch action occurs. Event arguments provide the following info:
- Timestamp: identify the touch event by time
- GetTouchPoints function (over specific UI Element)
- GetPrimaryTouchPoint function (over specific UIElement)
- SuspendMousePromotionUntilTouchUp function
- GetTouchPoints returns TouchPointCollection
In TouchPointCollection first point in the collection is the PrimaryPoint. Each member in collection is TouchPoint. TouchPoint provides following info:
- Position
- Size
- TouchDevice
- Action
Action is from TouchAction enumeration
TouchDevice provides the following info
- Id: identification provided by operation system
- DirectlyOver: topmost UIElement under the point
Sample code for getting touch points and simple manipulation:
//Somewhere in code – subscription for touch events:
Touch.FrameReported += new TouchFrameEventHandler(Touch_FrameReported);
When event arrives:
void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
TouchPointCollection points = e.GetTouchPoints(null);
TouchPoint primaryPoint = e.GetPrimaryTouchPoint(null);
if (null != primaryPoint)
{
if (primaryPoint.Action == TouchAction.Down)
e.SuspendMousePromotionUntilTouchUp();
switch (primaryPoint.Action)
{
case TouchAction.Down:
//Business logic here...
break;
case TouchAction.Up:
//Business logic here...
break;
case TouchAction.Move:
//Business logic here...
break;
}
}
Now you application responds for touch events (if you lucky owned of touch-enabled computer) running Windows 7 :)
Enjoy,
Alex