雑記 - otherwise

最近はDQ10しかやっていないダメ技術者がちまちまと綴る雑記帳

わんくま東京勉強会 #64 アフターフォロー (20) : Gesture

Windows Phone の操作は基本的にタッチによって行われます。
ご存じの通り、タッチにはタップ、フリック、ピンチ等の色々なジェスチャアクションが存在しますが、アプリケーションで基本的なジェスチャをキャプチャするためのイベントが用意されています。
また、 Toolkit を使う事で更に色々なイベントをキャプチャ可能です。

SDK 標準で利用可能なイベント

SDK 標準では Tap, Double Tap, Hold イベントをキャプチャ出来ます。

XAML
<!-- 例えばボタンでキャプチャする -->
<Button x:Name="sampleButton" Content="ポチっとな"
        Tap="sampleButton_Tap"
        DoubleTap="sampleButton_DoubleTap"
        Hold="sampleButton_Hold"
    />
C#
// GestureEventArgs は System.Windows.Input 名前空間にあります

// Tap
void sampleButton_Tap(object sender, GestureEventArgs e)
{
}

//Double Tap
void sampleButton_DoubleTap(object sender, GestureEventArgs e)
{
}

//Hold
void sampleButton_Hold(object sender, GestureEventArgs e)
{
}

Toolkit で利用可能なイベント

Toolkit の GestureService を利用してイベントをキャプチャします。

XAML
<!-- toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit -->

<Button x:Name="sampleButton" Content="ポチっとな">
  <toolkit:GestureService.GestureListener>
    <toolkit:GestureListener
        Tap="sampleButton_Tap"
        DoubleTap="sampleButton_DoubleTap"
        Hold="sampleButton_Hold"
        Flick="sampleButton_Flick"
        DragDelta="sampleButton_DragDelta"
        PinchStarted="sampleButton_PinchStarted"
        PinchDelta="sampleButton_PinchDelta"
    />
  </toolkit:GestureService.GestureListener>
</Button>
C#
// Toolkit の GestureEventArgs は Microsoft.Phone.Controls 名前空間にあります
// ちょっとややこしいので注意

// Tap (on Toolkit)
void sampleButton_Tap(object sender, GestureEventArgs e)
{
}

// Double Tap (on Toolkit)
void sampleButton_DoubleTap(object sender, GestureEventArgs e)
{
}

// Hold (on Toolkit)
void sampleButton_Hold(object sender, GestureEventArgs e)
{
}

// Flick (on Toolkit)
void sampleButton_Flick(object sender, GestureEventArgs e)
{
}

// Pan (on Toolkit)
//  ※ Pan 操作は Drag と同等なので Drag イベントとして捕捉可能です
void sampleButton_DragDelta(object sender, DragDeltaGestureEventArgs e)
{
}

// Pinch 開始 (on Toolkit)
void sampleButton_PinchStarted(object sender, PinchStartedGestureEventArgs e)
{
}

// Pinch 中 (on Toolkit)
void sampleButton_PinchDelta(object sender, PinchGestureEventArgs e)
{
}