Search code examples
xamarin.formsuiscrollview

How to determine current scroll offset in xamarin forms


I have a horizontal scrollview with a button to scroll it leftwards all the way to the end. OR if it's scrolled all the way to the end already scroll it to the beginning. Hence two questions

  1. How do I determine scroll offset in xamarin? the very thing that maps to frame offset x on ios
  2. How do I determine the scroll amount

Solution

    1. You can determine the horizontal and vertical scroll offset using the ScrollX and ScrollY properties of your ScrollView. These are bindable, so if you're using MVVM you can map them to properties on your view model. If you're not using MVVM and want to react to changes in ScrollX or ScrollY, add a listener to the ScrollView's Scrolled event.

    2. To find the total height or width of the content in the ScrollView, use the ContentSize property. The Content property will give you the contained View itself.