Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SetFocusOnClickedBehavior.cs
1using System.ComponentModel;
2
4{
8 public class SetFocusOnClickedBehavior : Behavior<View>
9 {
13 [TypeConverter(typeof(ReferenceTypeConverter))]
14 public View? SetFocusTo { get; set; }
15
17 protected override void OnAttachedTo(View View)
18 {
19 if (View is Controls.ImageButton ImageButton)
20 ImageButton.Clicked += this.Button_Clicked;
21 else if (View is Button Button)
22 Button.Clicked += this.Button_Clicked;
23
24 base.OnAttachedTo(View);
25 }
26
28 protected override void OnDetachingFrom(View View)
29 {
30 if (View is Controls.ImageButton ImageButton)
31 ImageButton.Clicked -= this.Button_Clicked;
32 else if (View is Button Button)
33 Button.Clicked -= this.Button_Clicked;
34
35 base.OnDetachingFrom(View);
36 }
37
38 private void Button_Clicked(object? Sender, EventArgs e)
39 {
40 FocusOn(this.SetFocusTo!);
41 }
42
47 public static void FocusOn(View Element)
48 {
49 if (Element is not null && Element.IsVisible)
50 {
51 Element.Focus();
52
53 if (Element is Entry Entry && Entry.Text is not null)
54 Entry.CursorPosition = Entry.Text.Length;
55 }
56 }
57 }
58}
Used for moving focus to the next UI component when a button has been clicked.
static void FocusOn(View Element)
Sets focus on an element.