Being notified when listview is being scrolled up or down?

In the Essential Studio Volume 4. 

I could detect the ScrollStates for ScrollView in SfListView. 

It reports "ScrollState.Dragging", "ScrollState.Fling" and"ScrollState.Idle".

But how do i detect if the listview is being scroll up or being scrolled down by how many units. 

So i could implement a collapsing header that hide when the list was scrolled up and expand when the list was scrolled down.

Thanks.


1 Reply

MK Muthu Kumaran Gnanavinayagam Syncfusion Team December 11, 2017 01:16 PM UTC

Hi KITTIPAT, 
 
We have checked your requirement “Need to identify the scrolling direction to expand and collapse the GroupHeader” from our side. We would like to let you know that the scrolling direction could be identified in the ScrollView using 2 possible workarounds in sample level. 
 
Using ExtendedScrollView’s Changed event: 
 
In this event you get the ScrollY position from the ScrolledEventArgs using which you can perform Expand and Collapse operations as like below code example. 
 
public partial class GroupingPage : ContentPage 
    { 
        double scrollOffet; 
        double previousOffset; 
 
        public GroupingPage() 
        { 
            InitializeComponent(); 
            var scrollview = listView.GetScrollView(); 
            scrollview.Scrolled += Scrollview_Scrolled; 
        } 
 
        private void Scrollview_Scrolled(object sender, ScrolledEventArgs e) 
        { 
            scrollOffet = (double)container.GetType().GetRuntimeProperties().First(p => p.Name == "ScrollOffset").GetValue(container); 
            if (e.ScrollY == 0) 
                return; 
 
                if (previousOffset >= e.ScrollY) 
                    listView.CollapseGroup(listView.DataSource.Groups[1]); 
                else 
                    listView.ExpandGroup(listView.DataSource.Groups[1]); 
 
            previousOffset = e.ScrollY; 
        } 
    } 
 
Using ScrollStateChanged event: 
 
You can get the ScrollOffset value from the ScrollAxisBase and in the ScrollStateChanged event you can perform Expand and Collapse operations as like below code example. 
 
public partial class GroupingPage : ContentPage 
    { 
        VisualContainer container; 
        ScrollAxisBase scrollRows; 
        double scrollOffet; 
        double previousOffset; 
 
        public GroupingPage() 
        { 
            InitializeComponent(); 
            container = listView.GetVisualContainer(); 
            scrollRows = container.GetType().GetRuntimeProperties().First(p => p.Name == "ScrollRows").GetValue(container) as ScrollAxisBase; 
            listView.ScrollStateChanged += ListView_ScrollStateChanged; 
        } 
 
        private void ListView_ScrollStateChanged(object sender, ScrollStateChangedEventArgs e) 
        { 
            scrollOffet = (double)container.GetType().GetRuntimeProperties().First(p => p.Name == "ScrollOffset").GetValue(container); 
            if (scrollOffet == 0) 
                return; 
            if(e.ScrollState==ScrollState.Idle) 
            { 
                if (previousOffset >= scrollOffet) 
                    listView.CollapseGroup(listView.DataSource.Groups[1]); 
                else 
                    listView.ExpandGroup(listView.DataSource.Groups[1]); 
            } 
 
            previousOffset = scrollOffet; 
        } 
   } 
 
Please let us know if you require further assistance. 
 
Regards, 
G.Muthu Kumaran. 


Loader.
Up arrow icon