A swipe motion takes place when a little finger are relocated throughout the monitor in a horizontal or vertical path, and is frequently familiar with initiate routing through content material.

A swipe motion takes place when a little finger are relocated throughout the monitor in a horizontal or vertical path, and is frequently familiar with initiate routing through content material.

The rule instances here were obtained from the Swipe motion test.

To help make a see know a swipe gesture, create a SwipeGestureRecognizer case, arranged the course residential property to a SwipeDirection enumeration importance ( remaining , correct , right up , or Down ), optionally set the Threshold homes, manage the Swiped show, and create the gesture recognizer for the GestureRecognizers range on the view. These code sample shows a SwipeGestureRecognizer attached to a BoxView :

Here’s the similar C# signal:

The SwipeGestureRecognizer class comes with a limit land, that may be optionally set-to a uint price that symbolizes minimal swipe distance that must be gained for a swipe to get respected, in device-independent units. The default property value this land try 100, which means that any swipes being less than 100 device-independent models will be dismissed.

Identifying the swipe course

Within the advice above, the course homes is placed to single a value from the SwipeDirection enumeration. Butis also possible to put this land to multiple principles from the SwipeDirection enumeration, so your Swiped show was fired in reaction to a swipe much more than one direction. However, the constraint is one SwipeGestureRecognizer is only able to acknowledge swipes that occur for a passing fancy axis. Thus, swipes that take place throughout the horizontal axis can be identified by establishing the Direction homes to remaining and Appropriate :

Equally, swipes that occur on the vertical axis could be acquiesced by placing the path land to along :

As an alternative, a SwipeGestureRecognizer for every swipe course may be created to know swipes in every single course:

Here is the comparable C# rule:

Into the preceding wireclub emotes examples, the exact same show handler responds to the Swiped occasion shooting. However, each SwipeGestureRecognizer case can use another type of celebration handler if neccessary.

Responding to the swipe

A meeting handler when it comes down to Swiped celebration is found for the next instance:

The SwipedEventArgs is generally examined to look for the movement of swipe, with custom logic giving an answer to the swipe as required. The movement of this swipe can be had through the Direction house of this show arguments, which is set to among the values for the SwipeDirection enumeration. Additionally, the big event arguments have a Parameter homes which is set to the worth of the CommandParameter homes, if explained.

Making use of commands

The SwipeGestureRecognizer class also contains Command and CommandParameter characteristics. These attributes are typically used in programs which use the Model-View-ViewModel (MVVM) structure. The Command belongings defines the ICommand are invoked when a swipe gesture was respected, making use of CommandParameter homes identifying an object becoming passed away to your ICommand. These laws sample shows tips bind the order land to an ICommand defined for the see product whoever case is defined since the page BindingContext :

Very same XAML laws is:

SwipeCommand is actually a residential property of type ICommand explained for the see model instance that is set given that webpage BindingContext . When a swipe gesture are acknowledged, the perform technique of the SwipeCommand object will be executed. The argument on the perform method is the worth of the CommandParameter house. To learn more about commands, begin to see the demand screen.

Producing a swipe container

The SwipeContainer class, and is found when you look at the soon after rule sample, was a general swipe acceptance lessons that be covered around a View to perform swipe motion acceptance:

The SwipeContainer course produces SwipeGestureRecognizer things for several four swipe directions, and attaches Swipe celebration handlers. These celebration handlers invoke the Swipe show explained because of the SwipeContainer .

Listed here XAML laws sample reveals the SwipeContainer lessons covering a BoxView :

This amazing code example reveals how SwipeContainer wraps a BoxView in a C# page:

Whenever BoxView receives a swipe gesture, the Swiped occasion during the SwipeGestureRecognizer was fired. This is certainly taken care of by SwipeContainer class, which fires its very own Swipe show. This Swipe occasion try taken care of on the webpage. The SwipedEventArgs can then be evaluated to look for the direction in the swipe, with custom reason responding to the swipe as required.

Leave a Comment

อีเมลของคุณจะไม่แสดงให้คนอื่นเห็น ช่องข้อมูลจำเป็นถูกทำเครื่องหมาย *