Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
TemplatedButton.cs
1using System.Windows.Input;
3
5{
9 public class TemplatedButton : ContentView, IButtonElement
10 {
14 public TemplatedButton() :
15 base()
16 {
17 TapGestureRecognizer TapRecognizer = new();
18 TapRecognizer.Tapped += this.OnTapped;
19 this.GestureRecognizers.Add(TapRecognizer);
20 }
21
22 readonly WeakEventManager onClickedEventManager = new();
23
27 public static readonly BindableProperty CommandProperty = ButtonElement.CommandProperty;
28
32 public static readonly BindableProperty CommandParameterProperty = ButtonElement.CommandParameterProperty;
33
40 public ICommand? Command
41 {
42 get => (ICommand?)this.GetValue(CommandProperty);
43 set => this.SetValue(CommandProperty, value);
44 }
45
50 public object? CommandParameter
51 {
52 get => this.GetValue(CommandParameterProperty);
53 set => this.SetValue(CommandParameterProperty, value);
54 }
55
56 void ICommandElement.CanExecuteChanged(object? sender, EventArgs e) => this.RefreshIsEnabledProperty();
57
58 void IButtonElement.PropagateUpClicked() => this.onClickedEventManager.HandleEvent(this, EventArgs.Empty, nameof(Clicked));
59
60 protected override bool IsEnabledCore => base.IsEnabledCore && CommandElement.GetCanExecute(this);
61
65 public event EventHandler Clicked
66 {
67 add => this.onClickedEventManager.AddEventHandler(value);
68 remove => this.onClickedEventManager.RemoveEventHandler(value);
69 }
70
71 private void OnTapped(object? Sender, EventArgs e)
72 {
73 this.Animate("Blink", new Animation()
74 {
75 { 0, 0.5, new((value) => this.Scale = value, 1, 0.95, Easing.CubicOut) },
76 { 0.5, 1, new((value) => this.Scale = value, 0.95, 1, Easing.CubicOut) },
77 });
78
79 ButtonElement.ElementClicked(this, this);
80 }
81 }
82}
TemplatedButton represents a generalization of a Button whose appearance is defined by a ControlTempl...
TemplatedButton()
Initializes a new instance of TemplatedButton class.
EventHandler Clicked
Occurs when the button is clicked/tapped.
ICommand? Command
Gets or sets the command to invoke when the button is activated. This is a bindable property.
object? CommandParameter
Gets or sets the parameter to pass to the Command property. The default value is null....
static readonly BindableProperty CommandProperty
The backing store for the Command bindable property.
static readonly BindableProperty CommandParameterProperty
The backing store for the CommandParameter bindable property.