,

UIElement Touch Gesture Events

Gestures are a high-level way of interpreting touch input data and include a set of common motions, such as tapping, flicking, and pinching. Controls, such as the WebBrowser, handle gestures such as the pinch gesture internally, allowing the user to pan and zoom in and out of content. By responding to gestures, you can provide a natural and immersive experience for your users.

Support for basic single touch gestures is incorporated into the Windows Phone SDK for XAML apps. Support for more complex gestures is provided by the Windows Phone Toolkit, discussed in the next section.

The sample code for this section is located in the UIElementTouchEventsView.xaml and UIElementTouchEventsView.xaml.cs files, in the Touch directory of the WPUnleashed. Examples project.

The UIElement class comes equipped to handle the following three touch gestures:

Image Tap

Image Double tap

Image Hold

The UIElement includes three corresponding routed events: Tap, DoubleTap, and Hold.

The three tap events can be subscribed to in XAML, as the following excerpt demonstrates:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <Border
        Tap="HandleTap"
        DoubleTap="HandleDoubleTap"
        Hold="HandleHold"
        Height="100"
        Width="200"
        Background="{StaticResource PhoneChromeBrush}">
        <TextBlock x:Name="textBlock"
                    HorizontalAlignment="Center" VerticalAlignment="Center"
                    Style="{StaticResource PhoneTextLargeStyle}"/>
    </Border>
</Grid>

Figure 12.2 shows the sample page responding to the double tap gesture.

Image

FIGURE 12.2 UIElementTouchEventsView page.

Event handlers for all three events share the same signature and accept a GestureEventArgs object. GestureEventArgs contains a Boolean Handled property, which allows you to stop the event from continuing to bubble up the visual tree, and a GetPosition method that allows you to retrieve the location coordinates of where the touch occurred.

Each tap gesture supported by UIElement is examined in the following sections.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.22.58