Xamarin.Forms - How can I dynamically change the height of my CarouselView?

Viewed 789

I have a CarouselView in which I call an object with individual and completely different Views.

The only elements my ContentPage has, are the CarouselView itself, and a bottombar with a gradient above it (notice gradient in following image).

I have done this in a way in which this gradient dissapears when the page's scrolling space becomes 0 (when I have scrolled to the end of the page).

The problem is that when I swipe between items in the CarouselView, the CarouselView always maintains the height of the very first View that is called in.

This means that, in a View with MORE height than the 1st one, when scrolling up (after being at the very bottom, and therefore not showing a gradient) the gradient will only show again once it hits the height value of the 1st page.

In a View with LESS height than the 1st one, the page will allow me to scroll down until I reach the height value of the 1st page, even if there are not enough elements on the page to even need a scroll.

Essentially, what I am asking for, is if there is a way in which I can, in some way, "refresh" the height of the Page every time a scroll is complete to another View in the CarouselView, resolving my height issues in smaller views, and my gradient issues in larger views.

Main ContentPage Code Behind (Gradient)

        public double ScrollingSpace
        {
            get
            {
                return MainScrollView.ContentSize.Height - MainScrollView.Height;
            }
            set { }
        }

        // Removes gradient when scroll is complete
        private void OnScrolled(object sender, ScrolledEventArgs e)
        {
            if (ScrollingSpace <= e.ScrollY) // Touched bottom
                EndPageGradient.SetValue(IsVisibleProperty, false); // the view is GONE, not invisible
            else
                EndPageGradient.SetValue(IsVisibleProperty, true);
        }

        // Removes gradient if page is not large enough to need scroll
        protected override void OnAppearing()
        {
            if (ScrollingSpace <= 0)
                EndPageGradient.SetValue(IsVisibleProperty, false); // the view is GONE, not invisible
        }

Main ContentPage CarouselView XAML

                <CarouselView
                    ItemsSource="{Binding ViewList}"
                    Loop="False">

                    <CarouselView.ItemTemplate>
                        <DataTemplate>
                            <ContentView Content="{Binding .}" />
                        </DataTemplate>
                    </CarouselView.ItemTemplate>

                </CarouselView>

Main ContentPage ViewModel (List with Views for CarouselView)

            ViewList = new List<ContentView>()
            {
                new Step1(),
                new Step2(),
                new Step3(),
                new Step4(),
                new Step5(),
                new Step6(),
                new Step7(),
                new Step8()
            };

Thanks in advance!

0 Answers
Related