xamarin.forms - Xamarin Forms:如何从 SwipeStarted 事件中获取 SwipeDirection 值?
问题描述
我swipeview
在我的项目中使用功能来刷flowlistviews
. 我的中心 flowlistview 需要左右滑动。我怎样才能做到这一点swipeview
?
我的代码:
<SwipeView
x:Name="SwipeView2"
SwipeStarted="CenterSwipeView"
IsVisible="False">
<SwipeView.RightItems>
<SwipeItems>
<SwipeItem/>
</SwipeItems>
</SwipeView.RightItems>
<flv:FlowListView>
//listview items
</flv:FlowListView>
</SwipeView>
public void CenterSwipeView(object sender, SwipeStartedEventArgs args)
{
//how can I get the SwipeDirection value here
}
我需要根据SwipeDirection
值(左或右)调用不同的函数。
另外,我试过了,SwipeGestureRecognizer
但它不适用于 flowlistview。
解决方案
您最好添加SwipeGestureRecognizer
而DataTemplate
不是整个 FlowListView(否则它将与 listview 的默认滚动事件冲突)。
<DataTemplate>
<StackLayout BackgroundColor="LightBlue" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<StackLayout.GestureRecognizers>
<SwipeGestureRecognizer Direction="Left" Command="{Binding xxx}"/>
<SwipeGestureRecognizer Direction="Right" Command="{Binding xxx}"/>
</StackLayout.GestureRecognizers>
// the elements
</StackLayout>
</DataTemplate>
更新
由于您在不使用 MVVM 的情况下处理 Code Behind 中的逻辑。您应该使用 swipe 事件而不是 command 。
<StackLayout.GestureRecognizers>
<SwipeGestureRecognizer Direction="Left" Swiped="SwipeGestureRecognizer_Swiped"/>
</StackLayout.GestureRecognizers>
private void SwipeGestureRecognizer_Swiped(object sender, SwipedEventArgs e)
{
// set List2 ...
}
此外,在您的情况下,最好的解决方案是使用 Tabbed Page 。默认情况下会支持这样的功能。
推荐阅读
- python - 在 Python Slack API 中使用装饰器
- azure - How to Auto Renew Message Timeout using ServiceBusTrigger in Azure Function with C#?
- caching - TYPO3 - 缓存问题 - 不仅仅是编辑的页面被“刷新”
- selenium - 将 Selenium / TestNG 的测试结果报告发布回 TFS 2015
- java - 错误:任务 ':app:transformClassesWithMultidexlistForDebug' ccid-1.1.5 执行失败
- google-apps-script - 如何在 Apps 脚本中捕获超出配额限制的错误
- node.js - 为什么弹性搜索批量操作对大量数据失败
- jquery - 裁剪器不在画布上显示第二张图像
- reactjs - 使用 React 在 Office.js 加载项中定义自定义函数
- python-3.x - 有没有更快的方法从 REST api 请求数据?