3
votes

I'm creating an app which includes a Stacklayout inside a Scrollview. In both I defined the Orientation as Vertical and the VerticalOptions as FillAndExpand. As described in here: https://forums.xamarin.com/discussion/20945/scrollview-in-xaml But the App won't scroll.

<ContentPage.Content>
    <AbsoluteLayout>
        <ScrollView Orientation="Vertical"
                    VerticalOptions="FillAndExpand">
            <StackLayout Margin="{StaticResource PageMargin}"
                         AbsoluteLayout.LayoutBounds="0.0, 0.0, 1.0, 1.0"
                         AbsoluteLayout.LayoutFlags="All"
                         Orientation="Vertical"
                         VerticalOptions="FillAndExpand">

                <Label Text="Lorem Ipsum..." />
                <!--Extra Labels-->
                <Label Text="Lorem Ipsum..." />

            </StackLayout>
        </ScrollView>

        <skia:SKCanvasView x:Name="BgCanvasView"
                           PaintSurface="OnBgCanvasViewPaintSurface"
                           AbsoluteLayout.LayoutBounds="0.0, 0.0, 1.0, 1.0"
                           AbsoluteLayout.LayoutFlags="All"
                           InputTransparent="True"/>
    </AbsoluteLayout>
</ContentPage.Content>

Do you got any ideas I could try?

Thank you in advance.

EDIT: I figured out it has something to do with the <AbsoluteLayout>. I created another Project for testing this issue. With the AbsoluteLayout same result as in my App. But without it the StackLayout scrolls as expected. Since the AbsoluteLayout is necessary for me, beacuse of the Background Graphics I draw in the SKCanvasView, missing it out isn't an Option.

EDIT: Well... I figured it out by myself and feel a bit dumb right now. The <Scrollview> was missing the AbsoluteLayout.LayoutBounds and the AbsoluteLayout.LayoutFlags

1

1 Answers

2
votes
  • Your going in a right direction just don't forget that if we want scroll-view to scroll then it is necessary that the content of scroll-view should overflow scroll-view bounds
  • currently your ScrollView and StackLayout both are in AbsoluteLayout with AbsoluteLayout.LayoutBounds = "All" this means height and width will be proportional to the screen or parent view.
  • Due to this StackLayout which is child element of your ScrollView will never grow larger than ScrollView bounds and ScrollView will never allow you to scroll the screen.

Please try following approch to implement Scrollview it might help

<AbsoluteLayout>
    <StackLayout AbsoluteLayout.LayoutBounds = "0,0,1,1" AbsoluteLayout.LayoutFlags = "All">
       <ScrollView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
          <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"></StackLayout>
       </ScrollView>
    </StackLayout>
    <skia:SKCanvasView x:Name="BgCanvasView"
                       PaintSurface="OnBgCanvasViewPaintSurface"
                       AbsoluteLayout.LayoutBounds="0.0, 0.0, 1.0, 1.0"
                       AbsoluteLayout.LayoutFlags="All"
                       InputTransparent="True"/>
</AbsoluteLayout>

I tried same code on my machine and scrollview is working properly for me