Create Scroll Position Behavior For Data Trigger
By default, the SfAccordion view will become a scrollview when the content is too large to fit the parent container. I would like to use this scroll position in a data trigger binding to fade in/out a sticky header when particular threshold is reached. I have done this previously using this SfListView behavior with an x:Name and XAML reference to the ScrollY position from the behavior. Can I do something like this with an SfAccordion view:
public class ListScrollBindingBehavior : Behavior<SfListView>
{
private ListViewScrollView scrollView = null!;
public double ScrollX
{
get => (double)GetValue(ScrollXProperty);
set => SetValue(ScrollXProperty, value);
}
public static BindableProperty ScrollXProperty = BindableProperty.Create(
nameof(ScrollX),
typeof(double),
typeof(ListScrollBindingBehavior),
0d,
BindingMode.TwoWay
);
public double ScrollY
{
get => (double)GetValue(ScrollYProperty);
set => SetValue(ScrollYProperty, value);
}
public static BindableProperty ScrollYProperty = BindableProperty.Create(
nameof(ScrollY),
typeof(double),
typeof(ListScrollBindingBehavior),
0d,
BindingMode.TwoWay
);
protected override void OnAttachedTo(SfListView bindable)
{
scrollView = bindable.GetScrollView();
scrollView.Scrolled += new EventHandler<ScrolledEventArgs>(OnScrolled);
scrollView.HorizontalScrollBarVisibility = ScrollBarVisibility.Never;
scrollView.VerticalScrollBarVisibility = ScrollBarVisibility.Never;
base.OnAttachedTo(bindable);
}
protected override void OnDetachingFrom(SfListView bindable)
{
scrollView.Scrolled -= new EventHandler<ScrolledEventArgs>(OnScrolled);
scrollView = null!;
base.OnDetachingFrom(bindable);
}
private void OnScrolled(object sender, ScrolledEventArgs e)
{
ScrollX = e.ScrollX;
ScrollY = e.ScrollY;
}
}
SIGN IN To post a reply.
1 Reply
RM
RiyasHameed MohamedAbdulKhader
Syncfusion Team
May 9, 2025 11:22 AM UTC
Hi Bryson Scales,
We would like to inform you that you can achieve the same functionality by accessing the first child of the SfAccordion, which is the ScrollView. Once you have the ScrollView, you can implement your logic accordingly. For your reference, we have attached the code snippet for your reference.
We would like to inform you that you can achieve the same functionality by accessing the first child of the SfAccordion, which is the ScrollView. Once you have the ScrollView, you can implement your logic accordingly. For your reference, we have attached the code snippet for your reference.
public class SfAccordionBehavior : Behavior<SfAccordion> { private ScrollView? scrollView; protected override void OnAttachedTo(SfAccordion bindable) { (bindable as SfAccordion).Loaded += SfAccordionBehavior_Loaded; base.OnAttachedTo(bindable); } private void SfAccordionBehavior_Loaded(object? sender, EventArgs e) { scrollView = (sender as SfAccordion)!.Children.FirstOrDefault() as ScrollView; if (scrollView != null) { scrollView.Scrolled += new EventHandler<ScrolledEventArgs>(OnScrolled); scrollView.HorizontalScrollBarVisibility = ScrollBarVisibility.Never; scrollView.VerticalScrollBarVisibility = ScrollBarVisibility.Never; } } protected override void OnDetachingFrom(SfAccordion bindable) { scrollView!.Scrolled -= new EventHandler<ScrolledEventArgs>(OnScrolled); scrollView = null!; (bindable as SfAccordion).Loaded -= SfAccordionBehavior_Loaded; base.OnDetachingFrom(bindable); } private void OnScrolled(object? sender, ScrolledEventArgs e) { // your logic here } } |
Regards,
Riyas Hameed M
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
BS Bryson Scales
- May 8, 2025 05:17 PM UTC
- May 9, 2025 11:22 AM UTC