Silverlight 3 Quick Tip: Multitouch support on Windows 7

July 10, 2009

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

  • Up
  • Down
  • Move

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)

        switch (primaryPoint.Action)
          case TouchAction.Down:
            //Business logic here...

          case TouchAction.Up:
            //Business logic here...

          case TouchAction.Move:
            //Business logic here...

Now you application responds for touch events (if you lucky owned of touch-enabled computer) running Windows 7 🙂




Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>