Documentos de Académico
Documentos de Profesional
Documentos de Cultura
“GESTURE”
Pág. 1
Layouts
Laboratorio: GESTURE
COMPETENCIAS
INTRODUCCIÓN
PREPARACIÓN
Pág. 2
Layouts
TAP
Agregar página de contenido de nombre TapDemo.xaml
tapped.jpg
tapped_bw.jpg
</StackLayout>
</ContentPage.Content>
</ContentPage>
Agregar código C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Pág. 3
Layouts
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Ejercicio06
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class TapDemo : ContentPage
{
public TapDemo ()
{
InitializeComponent ();
var image = new Image
{
Source = "tapped.jpg",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.CenterAndExpand,
};
Children =
{
image,
label
}
};
}
int tapCount;
readonly Label label;
void OnTapGestureRecognizerTapped(object sender, EventArgs args)
{
tapCount++;
label.Text = String.Format("{0} tap{1} so far!",
tapCount,
tapCount == 1 ? "" : "s");
Pág. 4
Layouts
Pág. 5
Layouts
PINCH
Agregar página de contenido de nombre PinchDemo.xaml
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
using Xamarin.Forms.Internals;
Pág. 6
Layouts
namespace Ejercicio06
{
public class PinchToZoomContainer : ContentView
{
double currentScale = 1;
double startScale = 1;
double xOffset = 0;
double yOffset = 0;
public PinchToZoomContainer()
{
var pinchGesture = new PinchGestureRecognizer();
pinchGesture.PinchUpdated += OnPinchUpdated;
GestureRecognizers.Add(pinchGesture);
}
Pág. 7
Layouts
}
if (e.Status == GestureStatus.Completed)
{
// Store the translation delta's of the wrapped user interface element.
xOffset = Content.TranslationX;
yOffset = Content.TranslationY;
}
}
}
}
Pág. 8
Layouts
PAN
Agregar página de contenido de nombre PanDemo.xaml
MonoMonkey.jpg
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
namespace Ejercicio06
{
public class PanContainer : ContentView
{
double x, y;
public PanContainer()
{
// Set PanGestureRecognizer.TouchPoints to control the
// number of touch points needed to pan
var panGesture = new PanGestureRecognizer();
panGesture.PanUpdated += OnPanUpdated;
GestureRecognizers.Add(panGesture);
}
Pág. 9
Layouts
case GestureStatus.Running:
// Translate and ensure we don't pan beyond the wrapped user interface element
bounds.
Content.TranslationX = Math.Max(Math.Min(0, x + e.TotalX),
-Math.Abs(Content.Width - App.ScreenWidth));
Content.TranslationY = Math.Max(Math.Min(0, y + e.TotalY),
-Math.Abs(Content.Height - App.ScreenHeight));
break;
case GestureStatus.Completed:
// Store the translation applied during the pan
x = Content.TranslationX;
y = Content.TranslationY;
break;
}
}
}
}
Pág. 10
Layouts
SWIPE
Agregar página de contenido de nombre SwipeDemo.xaml
Agregar código C#
Pág. 11
Layouts
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Ejercicio06
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class SwipeDemo : ContentPage
{
public SwipeDemo ()
{
InitializeComponent ();
}
void OnSwiped(object sender, SwipedEventArgs e)
{
_label.Text = $"You swiped: {e.Direction.ToString()}";
}
}
}
SWIPE BINDING
Agregar página de contenido de nombre SwipeBinding.xaml
using System;
using System.Collections.Generic;
Pág. 12
Layouts
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Text;
using System.Windows.Input;
using Xamarin.Forms;
namespace Ejercicio06
{
public class SwipeCommandPageViewModel : INotifyPropertyChanged
{
public ICommand SwipeCommand => new Command<string>(Swipe);
public SwipeCommandPageViewModel()
{
SwipeDirection = "You swiped: ";
}
#region INotifyPropertyChanged
#endregion
}
}
Pág. 13
Layouts
Agregar código C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Ejercicio06
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class SwipeBinding : ContentPage
{
public SwipeBinding ()
{
InitializeComponent ();
BindingContext = new SwipeCommandPageViewModel();
}
}
}
Pág. 14