2012-03-28 12 views
1

ジェスチャーハンドリングに問題があります。WP7 TouchPanelジェスチャー処理

私は主にこのチュートリアルの後にそれをやった:

http://www.nickharris.net/2010/11/using-touchpanel-for-gestures-in-windows-phone-7/

これは私のRemote.xamlファイルです:

<UserControl x:Class="EnergyRadio.Remote" 
.... 
ManipulationCompleted="StackPanel_ManipulationCompleted"> 
     <Grid x:Name="LayoutRoot" Background="Transparent" > 
     </Grid> 
</UserControl> 

そして、これはRemote.xaml.csです:

public Remote() 
    { 
     InitializeComponent(); 
     TouchPanel.EnabledGestures = GestureType.VerticalDrag | GestureType.HorizontalDrag; 
    } 

    private void StackPanel_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e) 
    { 
     //Check if touch Gesture is available 
     if (TouchPanel.IsGestureAvailable) 
     { 
      // Read the gesture so that you can handle the gesture type 
      GestureSample gesture = TouchPanel.ReadGesture(); 
      switch (gesture.GestureType) 
      { 
       case GestureType.VerticalDrag: 
        MessageBox.Show("vertikal"); 
        break; 
       case GestureType.HorizontalDrag: 
        MessageBox.Show("horizontal"); 
        break; 
       default: 
        //do something 
        break; 
      } 
     } 
    } 

電話をかけて自分の指をどのようにスワイプしても元に戻すことができます。しかし、これは最初のステップだったはずです。私が実際に必要とするのは4つの方向です...それは上下左右の意味です。

しかし、私はそう誰もがアイデアを持っていない。これgesturtypesを見つけるカント?

それは次のようになります。

  switch (gesture.GestureType) 
      { 
       case "GesturType.Up": 
        MessageBox.Show("Volume Up"); 
        break; 
       case "GesturType.Down": 
        MessageBox.Show("Volume Down"); 
        break; 
       case "GesturType.Right": 
        MessageBox.Show("Next Channel"); 
        break; 
       case "GesturType.Left": 
        MessageBox.Show("Previous Channel"); 
        break; 
       default: 
        //do something 
        break; 
      } 

感謝。

答えて

2

私はジェスチャーを処理する別の方法..ないXNAの方法を使用します。あなたは、uはあなたがこの

<Rectangle x:Name="HelloRect"> 
     <toolkit:GestureService.GestureListener> 
     <toolkit:GestureListener DragStarted="DragStarted_EventHandler" DragCompleted="DragCompleted_EventHandler" /> 
     </toolkit:GestureService.GestureListener> 
    </Rectangle> 

は、次に、あなたの背後にあるコードでジェスチャー

のためのイベントハンドラを持つことができない長方形の内側にドラッグイベントを検出したい例えばGestureService.GestureListener

を試すことができます

private void DragStarted_EventHandler(object sender, DragStartedGestureEventArgs e) 
{ 
    this.HelloRect.Fill = new SolidColorBrush(Colors.White); 
} 

private void DragCompleted_EventHandler(object sender, DragCompletedGestureEventArgs e) 
{ 
    this.HelloRect.Fill = new SolidColorBrush(Colors.Black); 
} 

アップデート:このチュートリアルでは良いです: http://windowsphonegeek.com/articles/WP7-GestureService-in-depth--key-concepts-and-API

あなたはreferenのいくつかをチェックしたい場合がありますあなたがイベントのparamsのために取得されます何のためのCES: http://www.mindscapehq.com/Help/PhoneElements/html/2f4dc2f0-f612-6a89-092e-f65c243caded.htmhttp://www.mindscapehq.com/Help/PhoneElements/html/96092851-e003-6423-389c-58d16281122b.htm

あなたがに見ることができますドラッグデルタイベントもあります。 希望どおりに助けてくれることを望みます。私はタッチパネルの事柄に慣れていません。それについて...あなたはもう少し返信を待つことができます

ドラッグの開始からドラッグの終了座標までAGAIN更新に

http://johnhforrest.com/2010/09/windows-phone-7-gestures/

別の良いチュートリアル..あなたがフリックイベントに探していると思うドラッグ

..私の方向を締結: FlickGestureEventArgsはタイプSystem.Windows.Controls.Orientationのある方向プロパティが含まれていますそこから

あなたはフリック

private void Flick_EventHandler(object sender, FlickGestureEventArgs e) 
{ 
    if (e.Direction == Orientation.Horizontal) 
    { 
     if (e.HorizontalVelocity < 0) 
     { 
      //Right flick 
     } 
     else 
     { 
      //Left flick 
     } 
    } 
    else 
    { 
     if (e.VerticalVelocity < 0) 
     { 
      //Up flick 
     } 
     else 
     { 
      //Down flick 
     } 
    } 
} 

幸運と良い夜の方向を決定することができます。..

更新:

私はちょうどあなたがGestureType列挙のためのスイッチの例を使用すべきではない見たが...彼らは整数型である

ジェスチャータイプのリストについては、

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.touch.gesturetype.aspx

+0

を見ますどうもありがとう!私はそれを試してみます。しかし、今私は別のプロジェクトが進行中ですので、私はそれを月曜日まで試すことはできません。 – MrTouch

+0

私はflickイベントを実装しようとしました。しかし、私は何も起こりませんデバッグしようとすると...イベントを認識しません...または彼は私はちょうど電話でフリックしたことを理解していない...それはあなたが提案した他の人と同じです... – MrTouch

+1

私はxaml内のツールキットの周囲にRectangleを追加する必要がありました。しかし、今それは動作します!ありがとうalot :) – MrTouch

関連する問題