Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ScrollToClickedBehavior.cs
1using System.ComponentModel;
2
4{
8 public class ScrollToClickedBehavior : Behavior<View>
9 {
13 [TypeConverter(typeof(ReferenceTypeConverter))]
14 public View? ScrollTo { get; set; }
15
19 public static readonly BindableProperty IsEnabledProperty =
20 BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(ScrollToClickedBehavior), true);
21
25 public bool IsEnabled
26 {
27 get => (bool)this.GetValue(IsEnabledProperty);
28 set => this.SetValue(IsEnabledProperty, value);
29 }
30
32 protected override void OnAttachedTo(View View)
33 {
34 if (View is Controls.ImageButton ImageButton)
35 ImageButton.Clicked += this.Button_Clicked;
36 else if (View is Button Button)
37 Button.Clicked += this.Button_Clicked;
38
39 base.OnAttachedTo(View);
40 }
41
43 protected override void OnDetachingFrom(View View)
44 {
45 if (View is Controls.ImageButton ImageButton)
46 ImageButton.Clicked -= this.Button_Clicked;
47 else if (View is Button Button)
48 Button.Clicked -= this.Button_Clicked;
49
50 base.OnDetachingFrom(View);
51 }
52
53 private void Button_Clicked(object? Sender, EventArgs e)
54 {
55 if (this.IsEnabled)
56 MakeVisible(this.ScrollTo!);
57 }
58
63 public static void MakeVisible(View Element)
64 {
65 Element Loop = Element.Parent;
66
67 while (Loop is not null && Loop is not ScrollView)
68 Loop = Loop.Parent;
69
70 (Loop as ScrollView)?.ScrollToAsync(Element, ScrollToPosition.MakeVisible, true);
71 }
72 }
73}
Used for moving focus to the next UI component when a button has been clicked.
static void MakeVisible(View Element)
Scrolls to make an element visible.
static readonly BindableProperty IsEnabledProperty
A BindableProperty for IsEnabled property.
bool IsEnabled
Gets or sets a value indicating if behavior is enabled or disabled