Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SetFocusOnTappedBehavior.cs
1using System.ComponentModel;
2
4{
8 public class SetFocusOnTappedBehavior : Behavior<View>
9 {
13 [TypeConverter(typeof(ReferenceTypeConverter))]
14 public View? SetFocusTo { get; set; }
15
17 protected override void OnAttachedTo(View View)
18 {
19 TapGestureRecognizer Tap = new();
20 View.GestureRecognizers.Add(Tap);
21 Tap.Tapped += this.Tap_Tapped;
22
23 base.OnAttachedTo(View);
24 }
25
27 protected override void OnDetachingFrom(View View)
28 {
29 foreach (IGestureRecognizer Gesture in View.GestureRecognizers)
30 {
31 if (Gesture is TapGestureRecognizer Tap)
32 {
33 Tap.Tapped -= this.Tap_Tapped;
34 View.GestureRecognizers.Remove(Tap);
35 break;
36 }
37 }
38
39 base.OnDetachingFrom(View);
40 }
41
42 private void Tap_Tapped(object? Sender, EventArgs e)
43 {
44 FocusOn(this.SetFocusTo);
45 }
46
51 public static void FocusOn(View? Element)
52 {
53 if (Element is not null && Element.IsVisible)
54 {
55 Element.Focus();
56
57 if (Element is Entry Entry && Entry.Text is not null)
58 Entry.CursorPosition = Entry.Text.Length;
59 }
60 }
61 }
62}
Used for moving focus to the next UI component when a view has been tapped.
static void FocusOn(View? Element)
Sets focus on an element.