A swipe gesture takes place when a hand is moved over the display screen in a horizontal or vertical way, and is also typically accustomed start navigation through content.

A swipe gesture takes place when a hand is moved over the display screen in a horizontal or vertical way, and is also typically accustomed start navigation through content.

The signal examples in this essay were obtained from the Swipe Gesture sample.

To manufacture a see know a swipe gesture, produce a SwipeGestureRecognizer case, put the Direction house to a SwipeDirection enumeration importance ( leftover , Right , right up , or Down ), optionally ready the limit home, handle the Swiped show, and add the motion recognizer with the GestureRecognizers range about view. The subsequent code example demonstrates a SwipeGestureRecognizer mounted on a BoxView :

Here’s the similar C# code:

The SwipeGestureRecognizer class also incorporates a limit belongings, which can be optionally set to a uint value that presents the minimum swipe distance that really must be obtained for a swipe becoming known, in device-independent devices. The standard property value this house are 100, which means any swipes which can be under 100 device-independent models will be ignored.

Recognizing the swipe course

Within the examples above, the path property is placed to single an advantages from the SwipeDirection enumeration. Butis also feasible to set this house to several values from the SwipeDirection enumeration, in order that the Swiped occasion is fired in response to a swipe in more than one course. But the restriction would be that one SwipeGestureRecognizer can only identify swipes that take place on a single axis. For that reason, swipes that occur on horizontal axis is generally acquiesced by placing the movement property to Left and Appropriate :

Similarly, swipes that take place throughout the straight axis is acquiesced by setting the way belongings to up-and-down :

Instead, a SwipeGestureRecognizer each swipe movement tends to be designed to accept swipes in every single path:

Here is the equivalent C# laws:

Inside earlier examples, the same show handler reacts to the Swiped occasion shooting. But each SwipeGestureRecognizer instance can use an alternative show handler if neccessary.

Replying to the swipe

An event handler the Swiped show is actually found during the preceding instance:

The SwipedEventArgs tends to be examined to discover the direction associated with the swipe, with custom logic answering the swipe as needed. The movement in the swipe can be had from path house from the show arguments, which will be set to among the many beliefs on the SwipeDirection enumeration. And also, case arguments also have a Parameter property which will be set to the value of the CommandParameter belongings, if explained.

Using directions

The SwipeGestureRecognizer lessons also incorporates Command and CommandParameter land. These qualities are typically included in software that use the Model-View-ViewModel (MVVM) design. The Command home defines the ICommand to be invoked when a swipe gesture try respected, with the CommandParameter belongings determining an object are passed away into ICommand. The next rule instance reveals just how to join the Command homes to an ICommand defined into the see model whoever case is scheduled as page BindingContext :

The equivalent XAML code is:

SwipeCommand try real estate of kind ICommand defined in view unit example that’s arranged due to the fact page BindingContext . When a swipe gesture was recognized, the perform method of the SwipeCommand object would be executed. The debate towards the perform method is the value of the CommandParameter house. For more information about directions, begin to see the Command user interface.

Generating a swipe container

The SwipeContainer class, and is shown for the following signal sample, try a general swipe identification class that be covered around a see to execute swipe gesture acceptance:

The SwipeContainer class brings SwipeGestureRecognizer objects for many four swipe information, and connects Swipe show handlers. These celebration handlers invoke the Swipe show defined of the SwipeContainer .

The subsequent XAML laws sample demonstrates the SwipeContainer class covering a BoxView :

This amazing laws instance reveals how the SwipeContainer wraps a BoxView in a C# webpage:

Whenever BoxView receives a swipe motion, the Swiped event in SwipeGestureRecognizer try discharged. This will be managed by SwipeContainer lessons, which fires its Swipe event. This Swipe occasion is actually managed from the webpage. The SwipedEventArgs are able to getting examined to look for the direction from the swipe, with custom reasoning addressing the swipe as needed.

Comentarios

Aún no hay comentarios. ¿Por qué no comienzas el debate?

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *