Xamarin Forms 向左滑动/向右滑动手势 [英] Xamarin Forms Swipe Left/Swipe Right Gestures

查看:71
本文介绍了Xamarin Forms 向左滑动/向右滑动手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我想说我对移动开发、Xamarin、C#、.Net 完全陌生.

I want to preface this by saying I'm completely new to mobile development, Xamarin, C#, .Net.

我正在使用 Xamarain Forms 创建一个移动应用程序,但遇到了无法使用滑动手势的问题,至少根据我看到的文档是这样.

I'm working on creating a mobile app using Xamarain Forms and have run into the problem of not having the swipe gesture available to me, at least according to the documentation I've seen.

我找到了这个网站:http://arteksoftware.com/gesture-recognizers-with-xamarin-forms/

这里描述了如何为 IOS/Android 添加一些额外的手势,以便在表单的上下文中访问.在我尝试遵循此之前,我想看看是否有其他人在 Xamarin Forms 应用中实现了滑动,以及他们是如何实现的.

This describes how to add some additional gestures for IOS/Android to be accessible in the context of the form. Before I try to follow this, I wanted to see if anyone else has implemented swipe in a Xamarin Forms app and how they went about it.

我的目标是必须有一个水平堆栈布局.此布局包含 7 个按钮,每个按钮反映当前一周中的一天.在堆栈布局上向左滑动会将按钮的文本更改为前一周.向右滑动会将按钮的文本更改为下周.

My goals are that there has to be a horizontal stack layout. This layout contains 7 buttons, each button reflects a day in the current week. Swiping left on the stack layout will change the button's text to the previous week. Swiping right will change the button's text to the next week.

所以我也在尝试为此和 XAML 使用 MVVM.那么我可以将向左滑动和向右滑动动作分开吗?我想使用 ICommand 根据滑动方向将某个参数传递给函数.

So I'm also trying to use MVVM for this and XAML. So is it possible for me to separate the swipe left and the swipe right action? I want to use ICommand to pass a certain parameter to a function based on the direction of the swipe.

我们将不胜感激任何此类示例或任何建议.

Any examples of this or any advice would be greatly appreciated.

推荐答案

Xamarin.Forms 引入了 SwipeGestureRecognizer :

Xamarin.Forms has introduced SwipeGestureRecognizer :

<BoxView Color="Teal" ...>
    <BoxView.GestureRecognizers>
        <SwipeGestureRecognizer Direction="Left" Swiped="OnSwiped"/>
    </BoxView.GestureRecognizers>
</BoxView>

这篇关于Xamarin Forms 向左滑动/向右滑动手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆