Visar inlägg med etikett contact. Visa alla inlägg
Visar inlägg med etikett contact. Visa alla inlägg

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.


fredag 23 januari 2009

Contact: The act or state of touching

While being in contact with the Surface you handle more information than when just placing your finger on a traditional touch-enabled screen. A Contact in ‘Microsoft Surface language’ is the kind of object that touches your Surface screen. The Surface SDK gives you the possibility to recognize different kinds of objects. The ones you can use are Finger, Tagged object or Blob.
  • Finger is self-explanatory; your finger in touch with the touch-enabled screen.
  • Tagged object are objects with an identity tag placed on them. This makes it possible to interpret exactly which object is being placed on the surface table.
  • Blob is an arbitrary object placed on the screen. You might have seen the demo with a wine glass with a surrounding aura – voila a blob.
Ok, so what to do with contacts. The touch-enabled controls for Surface can handle events from user interactions – that is different states of the contacts on the screen. These interactions are called gestures or manipulations.

Gestures are user activity which doesn’t work differently on whatever element is affected. A tapping or pressing action is a tap or push whether it’s a button or custom user control. Manipulations on the other hand are interactions that depend on what control is being touched and how. A manipulation user action has a context. That means that for one control a twirling motion means to rotate the control, but for another the same user interaction means to twist the control’s content.

Using the WPF layer of the Surface SDK the Surface controls are enabled to capture the following events:
  • ContactDown
  • ContactUp
  • ContactTapGesture
  • ContactHoldGesture
  • ContactEnter
  • ContactLeave
  • ContactChanged
More about the mentioned contact events when we come back to the WPF layer in a coming blog posts.