summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core/TapGestureRecognizer.cs
blob: 8449f105675969d1b104ae2802e01f831c9146aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Windows.Input;

namespace Xamarin.Forms
{
	public sealed class TapGestureRecognizer : GestureRecognizer
	{
		public static readonly BindableProperty CommandProperty = BindableProperty.Create("Command", typeof(ICommand), typeof(TapGestureRecognizer), null);

		public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create("CommandParameter", typeof(object), typeof(TapGestureRecognizer), null);

		public static readonly BindableProperty NumberOfTapsRequiredProperty = BindableProperty.Create("NumberOfTapsRequired", typeof(int), typeof(TapGestureRecognizer), 1);

		public TapGestureRecognizer()
		{
		}

		public ICommand Command
		{
			get { return (ICommand)GetValue(CommandProperty); }
			set { SetValue(CommandProperty, value); }
		}

		public object CommandParameter
		{
			get { return GetValue(CommandParameterProperty); }
			set { SetValue(CommandParameterProperty, value); }
		}

		public int NumberOfTapsRequired
		{
			get { return (int)GetValue(NumberOfTapsRequiredProperty); }
			set { SetValue(NumberOfTapsRequiredProperty, value); }
		}

		public event EventHandler Tapped;

		internal void SendTapped(View sender)
		{
			ICommand cmd = Command;
			if (cmd != null && cmd.CanExecute(CommandParameter))
				cmd.Execute(CommandParameter);

			EventHandler handler = Tapped;
			if (handler != null)
				handler(sender, new TappedEventArgs(CommandParameter));

#pragma warning disable 0618 // retain until TappedCallback removed
			Action<View, object> callback = TappedCallback;
			if (callback != null)
				callback(sender, TappedCallbackParameter);
#pragma warning restore
		}

		#region obsolete cruft

		// call empty constructor to hack around bug in mono where compiler generates invalid IL
		[Obsolete("Obsolete in 1.0.2. Use Command instead")]
		public TapGestureRecognizer(Action<View, object> tappedCallback) : this()
		{
			if (tappedCallback == null)
				throw new ArgumentNullException("tappedCallback");
			TappedCallback = tappedCallback;
		}

		// call empty constructor to hack around bug in mono where compiler generates invalid IL
		[Obsolete("Obsolete in 1.0.2. Use Command instead")]
		public TapGestureRecognizer(Action<View> tappedCallback) : this()
		{
			if (tappedCallback == null)
				throw new ArgumentNullException("tappedCallback");
			TappedCallback = (s, o) => tappedCallback(s);
		}

		[Obsolete("Obsolete in 1.0.2. Use Command instead")] public static readonly BindableProperty TappedCallbackProperty = BindableProperty.Create("TappedCallback", typeof(Action<View, object>),
			typeof(TapGestureRecognizer), null);

		[Obsolete("Obsolete in 1.0.2. Use Command instead")]
		public Action<View, object> TappedCallback
		{
			get { return (Action<View, object>)GetValue(TappedCallbackProperty); }
			set { SetValue(TappedCallbackProperty, value); }
		}

		[Obsolete("Obsolete in 1.0.2. Use Command instead")] public static readonly BindableProperty TappedCallbackParameterProperty = BindableProperty.Create("TappedCallbackParameter", typeof(object),
			typeof(TapGestureRecognizer), null);

		[Obsolete("Obsolete in 1.0.2. Use Command instead")]
		public object TappedCallbackParameter
		{
			get { return GetValue(TappedCallbackParameterProperty); }
			set { SetValue(TappedCallbackParameterProperty, value); }
		}

		#endregion
	}
}