Jose
Jose

Reputation: 65

Listview Y scroll position

Is there a way to get listview Y scroll position? My goal is to change TranslationY property of an image while the user scrolls the listview. I have achieved this before using a scrollview:

outerScrollView.Scrolled += (sender, e) => {
    var imageHeight = 800;
    var scrollRegion = layeringGrid.Height - outerScrollView.Height;
    var parallexRegion = imageHeight - outerScrollView.Height;
    var factor = outerScrollView.ScrollY - parallexRegion * (outerScrollView.ScrollY / scrollRegion);
    imagesCarousel.TranslationY = factor;
};

However, listview does not contains the Scrolled event.

Thanks in advance.

Upvotes: 3

Views: 2412

Answers (1)

MarchalPT
MarchalPT

Reputation: 1576

ListViews by default have a scroll, don't know why your ListView doesn't contain the Scrolled event.

However once your ListView doesn't have a scroll by default you must create a scrollview covering you ListView in the xml like this:

<ScrollView x:Name="outerScrollView">
    <ListView 
        x:Name="ItemsListView"  
        ItemsSource="{Binding Messages}" 
        HasUnevenRows="True" 
        />
</ScrollView>

Then once you are in a event e, instead of outerScrollView.ScrollY you should use e.ScrollY

Implementing it in your code above should be something like this:

outerScrollView.Scrolled += (sender, e) => {
    var imageHeight = 800;
    var scrollRegion = layeringGrid.Height - e.Height;
    var parallexRegion = imageHeight - e.Height;
    var factor = e.ScrollY - parallexRegion * (e.ScrollY / scrollRegion);
    imagesCarousel.TranslationY = factor;
};

That is it you have your scroll vertical position!!

Upvotes: 0

Related Questions