4

I've been scouring the web looking for examples on how to handle flick gestures on Windows Phone 7 in the ViewModel using MVVM Light.

I've found some good resources on handling commands from button clicks and such, but I can't seem to find anything on how to handle gestures. Anyone know if this is possible? If so, are there any good resources or can you provide a quick example how this could be done?

If not, I guess I'll just have to break down and put code in the code-behind. Ugh, makes me sick thinking of it. ;)

ctacke
  • 66,480
  • 18
  • 94
  • 155

2 Answers2

3

You can use the GestureListenerEx from Wp7Tools.

Add Wp7Tools to your project:

PM> install-package wp7tools

In your xaml:

<Rectangle Fill="Red" Width="100" Height="100">
    <toolkit:GestureService.GestureListener>
        <wp7:GestureListenerEx 
            OnTapAction="Tap"
            OnDragStartedAction="DragStart"
            OnDragCompletedAction="DragEnd"
            />
    </toolkit:GestureService.GestureListener>
</Rectangle>

And in your ViewModel:

public void Tap(GestureEventArgs e) {
    //Do something
}

public void DragStart(DragStartedGestureEventArgs e) {
    Debug.WriteLine(e.Direction);
}

public void DragEnd(DragCompletedGestureEventArgs e) {
    Debug.WriteLine(e.Direction);           
}

That's it. No code-behind, no commands, just point the method you want to be executed :)

andrecarlucci
  • 5,927
  • 7
  • 52
  • 58
0

How about making the control set you want to apply gestures to a user control?

Or even wrap a user control around the gesture listener then surface properties using dependency properties so you can bind to them

Steve Chadbourne
  • 6,873
  • 3
  • 54
  • 82