The low-level interface for touch is the TouchPoint
class. Unlike mouse events, the TouchPoint
class is designed exclusively for touch without a pointing device in mind. A TouchPoint
instance represents a finger touching the screen.
TouchPoint
has four read-only properties, described in the following list:
Action—Represents the type of manipulation and can have one of the three following values:
Down—Indicates that the user has made contact with the screen.
Move—Indicates that the touch point has changed position.
Up—Indicates that the touch point has been removed.
Position—Retrieves the X and Y coordinate position of the touch point, as a
System.Windows.Point
. This point is relative to the top-left corner of the element beneath the touch point.
Size—This is supposed to get the rectangular area that is reported as the touch-point contact area. The value reported on Windows Phone, however, always has a width and height of 1, making it of no use on the phone.
TouchDevice—Retrieves the specific device type that produced the touch point. This property allows you to retrieve the
UIElement
beneath the touch point via its TouchDevice.DirectlyOver
property. The TouchDevice.Id
property allows you to distinguish between fingers touching the display.
The Touch
class is an application-level service used to register for touch events. It contains a single public static member, the FrameReported
event. This event is global for your app and is raised whenever a touch event occurs.
To register for touch notifications, you subscribe to the Touch.FrameReported
event like so:
Touch.FrameReported += HandleFrameReported;
A handler for the FrameReported
event accepts a TouchFrameEventArgs
argument, as shown:
void HandleFrameReported(object sender, TouchFrameEventArgs args)
{
.../* method body */
}
A frame is a time slice where one or more touch events have occurred. When the FrameReported
event is raised, there may be up to four TouchPoint
objects.
TouchFrameEventArgs
contains four public members, which are described in the following list:
TimeStamp property—An
int
value that indicates when the touch event occurred.
GetPrimaryTouchPoint(UIElement relativeTo)—Retrieves the
TouchPoint
representing the first finger that touched the screen. A UIElement
can be specified to make the TouchPoint
object’s Position
property relative to that element. If a UIElement
is not specified (it is null), the returned TouchPoint
is relative to the top left of the page.
GetTouchPoints(UIElement relativeTo)—Retrieves the collection of
TouchPoints
for the frame. The UIElement
parameter works the same as the GetPrimaryTouchPoint
. The parameter does not restrict the set of TouchPoints
returned; all are returned and only the Position
of each TouchPoint
is affected.
SuspendMousePromotionUntilTouchUp()—Prevents touch events from turning into mouse events. See the following section for a more detailed explanation.
18.116.47.25