How to trigger an EventToCommand from a GestureLis

2019-06-25 05:10发布

问题:

Has anyone used a Toolkit.GestureListener to fire an EventToCommand?

回答1:

I don't think you can do it with the EventToCommand behaviour but I have created a behaviour that allows easy addition of the GestureListener by binding them to a command.

<Button  Content="Start"  
 Behaviour:GestureListenerBehaviours.TapCommand="{Binding   StartCommand}" />

I have only mapped the tap and the double tap but it should be easy to map the rest if required. Have a look at this link to get the source code

http://lazycowprojects.tumblr.com/post/10397441921/gesturelistenerbehaviourswp7



回答2:

It is not currently possible. GestureListener.Tap does not support this. I have an event handler in my code behind, which calls viewmodel method using datacontext:

 private void OnListItemTap(object sender, GestureEventArgs e)
 {
     var vm = DataContext as MyViewModel;
     if (vm != null)
     {
         vm.TapOnItem.Execute(listbox.SelectedItem);
     }
 }


标签: mvvm-light