/
ClickGestureRecognizer.cs
66 lines (52 loc) · 1.91 KB
/
ClickGestureRecognizer.cs
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
using System;
using System.ComponentModel;
using System.Windows.Input;
namespace Xamarin.Forms
{
[Flags]
public enum ButtonsMask
{
Primary = 1 << 0,
Secondary = 1 << 1
}
public sealed class ClickGestureRecognizer : GestureRecognizer
{
public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(ClickGestureRecognizer), null);
public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(ClickGestureRecognizer), null);
public static readonly BindableProperty NumberOfClicksRequiredProperty = BindableProperty.Create(nameof(NumberOfClicksRequired), typeof(int), typeof(ClickGestureRecognizer), 1);
public static readonly BindableProperty ButtonsProperty = BindableProperty.Create(nameof(Buttons), typeof(ButtonsMask), typeof(ClickGestureRecognizer), ButtonsMask.Primary);
public ClickGestureRecognizer()
{
}
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 NumberOfClicksRequired
{
get { return (int)GetValue(NumberOfClicksRequiredProperty); }
set { SetValue(NumberOfClicksRequiredProperty, value); }
}
public ButtonsMask Buttons
{
get { return (ButtonsMask)GetValue(ButtonsProperty); }
set { SetValue(ButtonsProperty, value); }
}
public event EventHandler Clicked;
[EditorBrowsable(EditorBrowsableState.Never)]
public void SendClicked(View sender, ButtonsMask buttons)
{
ICommand cmd = Command;
object parameter = CommandParameter;
if (cmd != null && cmd.CanExecute(parameter))
cmd.Execute(parameter);
Clicked?.Invoke(sender, new ClickedEventArgs(buttons, parameter));
}
}
}