onsdag 4 februari 2009

Touchability by Contact Events

An event describes an action which occurs in a specific behavior. To add ‘touchability’ to your Surface controls, contact events has to be registered for them. There are a couple of ways to add such contact handlers. The following examples show how to register a handler for capturing a press-and-hold event:

XAML:
<s:SurfaceSlider x:Name="MySurfaceSlider" ContactHoldGesture="MySurfaceSlider_ContactHoldGesture" />

C#, first option:
MySurfaceSlider.ContactHoldGesture += new ContactEventHandler(MySurfaceSlider_ContactHoldGesture);

C#, second option:
Contacts.AddContactHoldGestureHandler(MySurfaceSlider, MySurfaceSlider_ContactHoldGesture);

The implementation of the contact event handler:
private void MySurfaceSlider_ContactHoldGesture(object sender, ContactEventArgs e)
{ /* TODO: Handle Contact Hold Gesture event */ }

There are several events that are possible to capture. The following section lists the contact events that are supported in the Surface SDK (version 1.0):
  • ContactDown, which triggers when a contact is placed on a Surface control.
  • ContactUp, which triggers when a contact is removed from a Surface control.
  • ContactHoldGesture, which triggers when a Surface control is subject of a press-and-hold action. Note: Is only raised when the contact is of type Finger.
  • ContactTapGesture, which triggers when a Surface control is being tapped on.
  • ContactChanged, which triggers when a contact that is in touch with a Surface control changes its attributes, i.e. position.
  • ContactEnter, which triggers when a contact enters a control’s boundaries, i.e. if a finger (that is already in touch with the Surface) is moved onto a control.
  • ContactLeave, which triggers when contacts leaves a control’s boundaries.
I feel the ScatterViewItems’ ContactUp and ContactDown events needs a bit of extra information. ContactUp/Down are handled internally, which prevents you from raising any of the events. If you forget about this while working with ScatterViewItem this might be somewhat confusing. Another topic to keep in mind is the ScatterViewItems’ property ‘StaysActive’. If the property is set to ‘true’ this may affect the ScatterViewItem when a contact is released from it by the control not being deactivated.

Lastly I’ve posted a C# example of how to check what kind of contact is triggering a contact event.


1 kommentar:

  1. Hi, I'm busy building a surface application at the moment, and I was wondering if you can tell me what ContactTapGesture is? I presumed it would be a ContactDown followed by a ContactUp within a short time period, but I can't seem to make it work. Do you have any idea?

    SvaraRadera