diff options
author | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 13:02:25 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 16:13:41 -0700 |
commit | 17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch) | |
tree | b5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Core/TapGestureRecognizer.cs | |
download | xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2 xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip |
Initial import
Diffstat (limited to 'Xamarin.Forms.Core/TapGestureRecognizer.cs')
-rw-r--r-- | Xamarin.Forms.Core/TapGestureRecognizer.cs | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core/TapGestureRecognizer.cs b/Xamarin.Forms.Core/TapGestureRecognizer.cs new file mode 100644 index 00000000..0489985d --- /dev/null +++ b/Xamarin.Forms.Core/TapGestureRecognizer.cs @@ -0,0 +1,95 @@ +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)); + + Action<View, object> callback = TappedCallback; + if (callback != null) + callback(sender, TappedCallbackParameter); + } + + #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 + } +}
\ No newline at end of file |