简体   繁体   中英

Xamarin Forms - XAML - ScrollView contents overflows parent layout

I have a sample page that has an outer grid with 3 rows. first and last (top and bottom) are my Header and Footer sections and in the middle, I have a StackLayout which then has a Frame (for color) which then has a ScrollView and inside of it another StackLayout.

The most inner StackLayout has many items that need to be scrolled, however, my challenge is that the inner items inside a ScrollView->StackLayout are not being constrained by the bounds of its parent and just overflow on top of my header and footer.

Strangely enough, this has just started happening, it used to work just fine and I don't know what changed. Code wise, it's identical... I'm at a loss, please help... Below is my XAML

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Pro4Soft.MobileDevice.Plumbing.Screens.TestPage"
             VerticalOptions="FillAndExpand">
    <ContentView.Content>
        <Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Label x:Name="Title" Grid.Row="0" HorizontalTextAlignment="Center" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" FontAttributes="Bold" FontSize="Large">TEST PAGE</Label>
            <StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Row="1">
                <Frame BackgroundColor="LightYellow" BorderColor="LightYellow" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Padding="5">
                    <ScrollView x:Name="Scroller">
                        <StackLayout x:Name="Container" Orientation="Vertical" Padding="1">
                            <Label Text="SUMMY TEXT"></Label>
                            <Label Text="SUMMY TEXT"></Label>
                            <Label Text="SUMMY TEXT"></Label>
                            <Label Text="SUMMY TEXT"></Label>
                            <Label Text="SUMMY TEXT"></Label>
                            <Label Text="SUMMY TEXT"></Label>
                            <Label Text="SUMMY TEXT"></Label>
                            <Label Text="SUMMY TEXT"></Label>
                            <Label Text="SUMMY TEXT"></Label>
                            <Label Text="SUMMY TEXT"></Label>
                            <Label Text="SUMMY TEXT"></Label>
                            <Label Text="SUMMY TEXT"></Label>
                            <Label Text="SUMMY TEXT"></Label>
                            <Label Text="SUMMY TEXT"></Label>
                            <Label Text="SUMMY TEXT"></Label>
                            <Label Text="SUMMY TEXT"></Label>
                            <Label Text="SUMMY TEXT"></Label>
                        </StackLayout>
                    </ScrollView>
                </Frame>
            </StackLayout>
            <StackLayout x:Name="ControlsContainer" Orientation="Horizontal" Grid.Row="2" HeightRequest="50" HorizontalOptions="FillAndExpand">
                <Button Text="Some btn"/>
            </StackLayout>
        </Grid>
    </ContentView.Content>
</ContentView>

And here is a screenshot of what's going on

虚拟文本溢出父组件

在此处输入图片说明

I checked your code and it's working fine. ScrollView is working fine. Please see below screenshot.

在此处输入图片说明

Clean the project and delete bin/obj folder and try again.

I ended up building a brand new project and migrating old code over. Then it worked. I suspect an old Nuget, of unupdated Xamarin.Essentials package or something along those lines...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM