找到了我的问题的答案。
而不是 using toolkit:GestureListener
,我发现EventToCommand
with ManipulationDelta
orManipulationCompleted
也可以:
在 XAML 中
<i:Interaction.Triggers>
<i:EventTrigger EventName="ManipulationDelta">
<Command:EventToCommand Command="{Binding SlideOutDeltaCommand, Mode=OneWay}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
<i:EventTrigger EventName="ManipulationCompleted">
<Command:EventToCommand Command="{Binding SlideOutCompletedCommand, Mode=OneWay}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
通过将 EventArgs 传递给 ViewModel,您可以检测是否已发出滑动手势:
在视图模型中
定义中继命令
public RelayCommand<ManipulationDeltaEventArgs> SlideOutDeltaCommand
{
get;
private set;
}
定义 Execute() 方法
private void OnSlideDelta(ManipulationDeltaEventArgs e)
{
var delta = e.CumulativeManipulation.Translation;
//If Change in X > Change in Y, its considered a horizontal swipe
var isDeltaHorizontal = Math.Abs(delta.X) > Math.Abs(delta.Y) ? true : false;
}
在 ViewModel 构造函数中注册您的命令
public MainViewModel()
{
SlideOutDeltaCommand = new RelayCommand<ManipulationDeltaEventArgs>((e) => OnSlideDelta(e));
}