Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Detect moment when listView becomes scrollable

MikilllMikilll Member ✭✭✭

I need to programmatically detect the moment when the listView becomes scrollable, that means when it contains too many elements and a user can scroll it. Is there a way to achieve that, because I was searching for a long time over the Internet and I found nothing.

Thank you in advice!

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    That's a new/odd request. What about when the view just appears and it is already scrollable? That would be a state-change into becoming scrollable - it would start out that way.

    What's the end-goal here? What is it you want to achieve with this detection? Maybe there is a better way to go about it.

  • MikilllMikilll Member ✭✭✭
    edited June 2018

    @ClintStLaurent
    I have a problem with the footer in ListView. I want the footer to stay at the bottom of the screen when there are not too many elements in the Listview. When there are many elements in the listview and listview becomes scrollable I want the footer to be at the bottom of the listview and scroll with the listview. Right now I am only able to achieve this behavior by placing listview inside ScrollView, but this is not recommended solution by Xamarin. The recommended solution is to use listView "footer" property but using it I am not able to place a label at the bottom of the screen.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    So sometimes it will be at the bottom of the ListView (few items)
    And sometimes it will be at the end of the data (many items)
    Sounds like something that will piss off the users because of the inconsistent behavior - and behavior not like all the other apps on their phone. The point of using the Xamarin platform is people get the same CONSISTENT look and feel they know for each of their devices.

    You could probably check if the scroller in the ListView is visible.
    Or you could make a Behavior that places a Label at the bottom all the time, that has nothing to do with the footer.
    Or... add a real footer that is just dead space, and place a label ON TOP OF the LIstView at the bottom.

  • LandLuLandLu Member, Xamarin Team Xamurai

    @Mikilll You can try to calculate the content size of the list view, then compare it to the list view's height request. If it's larger then list view's actual height, it means it's scrollable.

  • MikilllMikilll Member ✭✭✭
    edited June 2018

    @LandLu said:
    @Mikilll You can try to calculate the content size of the list view, then compare it to the list view's height request. If it's larger then list view's actual height, it means it's scrollable.

    But how to calculate that if my listView has "HasUnevenRows=True"?

  • M_Shah04M_Shah04 USMember ✭✭✭

    @Mikilll you can try something like, count the total numbers of items displayed inside itemAppearing method(by just incrementing count when method called),
    As when the list will load, it will call this method in code behind for each cell displayed according to the screen size before you scroll the list.
    And if your list's itemsource count exceeds than this count then list is scrollable!
    Hope this may helps you.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    cc: @M_Shah04
    ScreenSize isn't enough though. What if the user has the magnification set higher than default, at an OS level? The ScreenSize would remain the same, but you'd only get half as many items.

  • M_Shah04M_Shah04 USMember ✭✭✭

    @ClintStLaurent said:
    cc: @M_Shah04
    ScreenSize isn't enough though. What if the user has the magnification set higher than default, at an OS level? The ScreenSize would remain the same, but you'd only get half as many items.

    But in this case also ultimately you will find that your list is scrollable or not, as if the magnification set higher it will display less number of cells and you need to scroll list for further cells so at the end you will get the number of items displayed before scroll.

  • VenkataSivaprasadReddyPulagamVenkataSivaprasadReddyPulagam USMember ✭✭✭
    edited June 2018

    @Mikilll

    Have you tried ListView events like "ItemAppearing" and "ItemDisappearing". This is an idea not the exact solution.
    Hope this might help.

    But be cautious as they triggers on the page appearing also.

    Thank you.

Sign In or Register to comment.