scrollview 没有向上滚动到足以看到其余视图 xamarin.forms

scrollview doesn't scroll up enough to see the rest of views xamarin.forms

我为注册页面编写了这段代码。在某些手机中,屏幕不适合所有视图,因此我使用了滚动视图,以便用户可以向下滚动它们。我面临的问题是滚动视图向上滚动不够。最后的按钮没有出现。这是我的 xaml 代码:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             x:Class="ALNahrainAlphaApp.RegisterPage"
             xmlns:controls="clr-namespace:ALNahrainAlphaApp;assembly=ALNahrainAlphaApp" 
             >
    <ContentPage.Content>
        
        <ScrollView Orientation="Vertical">
            <ScrollView.Background>
                <LinearGradientBrush EndPoint="0,1">
                    <GradientStop Color="#0d98ba"
                          Offset="0.2" />
                    <GradientStop Color="White"
                          Offset="1" />
                </LinearGradientBrush>
            </ScrollView.Background>
            <StackLayout>
            
            <Grid>

                <StackLayout>
                   


                    <Frame CornerRadius="50" BorderColor="White" BackgroundColor="Transparent" Margin="20,50">
                        <Grid Padding="1" ColumnSpacing="1" RowSpacing="0" Margin="0,160">

                            <Grid.RowDefinitions>
                                <RowDefinition Height="70" />
                                <RowDefinition Height="70" />
                                <RowDefinition Height="70" />
                                <RowDefinition Height="70" />
                                <RowDefinition Height="70" />
                                <RowDefinition Height="70" />
                                <RowDefinition Height="70" />

                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>


                                <ColumnDefinition Width="0.5*" />

                            </Grid.ColumnDefinitions>

                            <Frame CornerRadius="20" Margin="0,5" />

                            <controls:CustomEntry
                               
                                Grid.Row="0"
                                x:Name="id"
                                HorizontalOptions="FillAndExpand"
                                Margin="10,5"
                                TextColor="Black"
                       Placeholder="ID"
                                FontSize="16"
                    PlaceholderColor="Gray"
                      
                    />


                            <Frame CornerRadius="20"  Grid.Row="1"  Margin="0,5"/>
                            <controls:CustomEntry
                                
                                Grid.Row="1"
                                x:Name="firstname"
                                HorizontalOptions="Fill"
                                Margin="10,5"
                                TextColor="Black"
                                
                                FontSize="16"
                        Placeholder="First Name"
                    PlaceholderColor="Gray"
                      
                    />

                            <Frame CornerRadius="20"  Grid.Row="2"  Margin="0,5"/>
                            <controls:CustomEntry
                            
                                Grid.Row="2"
                                x:Name="lastname"
                                HorizontalOptions="Fill"
                                Margin="10,5"
                                TextColor="Black"
                        Placeholder="Last Name"
                    PlaceholderColor="Gray"
                                   FontSize="16"
                      
                    />
                            <Frame CornerRadius="20"  Grid.Row="3"  Margin="0,5"/>
                            <controls:CustomEntry
                                 FontSize="16"
                                Grid.Row="3"
                                x:Name="role"
                                HorizontalOptions="Fill"
                                Margin="10,5"
                                TextColor="Black"
                        Placeholder="Role"
                    PlaceholderColor="Gray"
                      
                    />
                            <Frame CornerRadius="20"  Grid.Row="4"  Margin="0,5"/>

                            <controls:CustomEntry
                                   FontSize="16"
                                Grid.Row="4"
                                x:Name="user_name"
                                HorizontalOptions="Fill"
                                Margin="10,5"
                                TextColor="Black"
                       
                       Placeholder="Username"
                    PlaceholderColor="Gray"
                    />


                            <Frame CornerRadius="20"  Grid.Row="5"  Margin="0,5"/>
                            <controls:CustomEntry
                                   FontSize="16"
                                Grid.Row="5"
                                x:Name="password"
                                HorizontalOptions="Fill"
                                Margin="10,5"
                                TextColor="Black"
                        Placeholder="Password"
                    PlaceholderColor="Gray"
                      
                    />


                            <StackLayout Orientation="Horizontal"      Grid.Row="6">
                                <Label Text="Allow Access" TextColor="Black"  FontSize="16" HorizontalOptions="Center" VerticalOptions="Center" Margin="15,5"/>
                                <Switch
                               
                           ThumbColor="Black"
                                    OnColor="White"
                                x:Name="appaccess"
                                HorizontalOptions="Center"
                                VerticalOptions="Center"
                                Margin="40,0"
                      
                    />
                            </StackLayout>
                        </Grid>
                    </Frame>
                    <Button CornerRadius="50" Text="Submit" FontSize="Medium" BackgroundColor="White" TextColor="Black"  FontFamily="audiofont" x:Name="save" HeightRequest="60" WidthRequest="140" HorizontalOptions="Center" VerticalOptions="Center" Margin="0,-85" Clicked="save_Clicked"/>
                </StackLayout>
                <Frame CornerRadius="50" HeightRequest="100" WidthRequest="100" HorizontalOptions="Center" VerticalOptions="Start"  Padding="-2"  BorderColor="White"  Margin="20,5,20,0">
                    <Image HeightRequest="150" WidthRequest="150" x:Name="userprofile"  HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
                </Frame>
            </Grid>

            </StackLayout>
        </ScrollView>

    </ContentPage.Content>
</ContentPage>

我尝试了不同的方法,我将滚动视图放在内容视图中,但我没有用。我做错了什么?

更改边距

  <Frame CornerRadius="50" BorderColor="White" BackgroundColor="Transparent" Margin="20,50">
                    <Grid Padding="1" ColumnSpacing="1" RowSpacing="0" Margin="0,90">

您可以尝试添加 属性 RowDefinitions 并为外网格定义两行。

         <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="100" />
            </Grid.RowDefinitions>
            <!--other code-->
         <Grid>

您可以参考以下代码:

<ContentPage.Content>

    <ScrollView Orientation="Vertical">
        <ScrollView.Background>
            <LinearGradientBrush EndPoint="0,1">
                <GradientStop Color="#0d98ba"
                      Offset="0.2" />
                <GradientStop Color="White"
                      Offset="1" />
            </LinearGradientBrush>
        </ScrollView.Background>
        <StackLayout>

            <Grid>
              <!--add two row here-->

            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="100" />
            </Grid.RowDefinitions>
                
                

              <StackLayout>


                <Frame CornerRadius="50" BorderColor="White" BackgroundColor="Transparent" Margin="20,50">
                        <Grid Padding="1" ColumnSpacing="1" RowSpacing="0" Margin="0,160">

                            <Grid.RowDefinitions>
                                <RowDefinition Height="70" />
                                <RowDefinition Height="70" />
                                <RowDefinition Height="70" />
                                <RowDefinition Height="70" />
                                <RowDefinition Height="70" />
                                <RowDefinition Height="70" />
                                <RowDefinition Height="70" />

                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>


                                <ColumnDefinition Width="0.5*" />

                            </Grid.ColumnDefinitions>

                            <Frame CornerRadius="20" Margin="0,5" />

                            <Entry
                           
                            Grid.Row="0"
                            x:Name="id"
                            HorizontalOptions="FillAndExpand"
                            Margin="10,5"
                            TextColor="Black"
                   Placeholder="ID"
                            FontSize="16"
                PlaceholderColor="Gray"
                  
                />


                            <Frame CornerRadius="20"  Grid.Row="1"  Margin="0,5"/>
                            <Entry
                            
                            Grid.Row="1"
                            x:Name="firstname"
                            HorizontalOptions="Fill"
                            Margin="10,5"
                            TextColor="Black"
                            
                            FontSize="16"
                    Placeholder="First Name"
                PlaceholderColor="Gray"
                  
                />

                            <Frame CornerRadius="20"  Grid.Row="2"  Margin="0,5"/>
                            <Entry
                        
                            Grid.Row="2"
                            x:Name="lastname"
                            HorizontalOptions="Fill"
                            Margin="10,5"
                            TextColor="Black"
                    Placeholder="Last Name"
                PlaceholderColor="Gray"
                               FontSize="16"
                  
                />
                            <Frame CornerRadius="20"  Grid.Row="3"  Margin="0,5"/>
                            <Entry
                             FontSize="16"
                            Grid.Row="3"
                            x:Name="role"
                            HorizontalOptions="Fill"
                            Margin="10,5"
                            TextColor="Black"
                    Placeholder="Role"
                PlaceholderColor="Gray"
                  
                />
                            <Frame CornerRadius="20"  Grid.Row="4"  Margin="0,5"/>

                            <Entry
                               FontSize="16"
                            Grid.Row="4"
                            x:Name="user_name"
                            HorizontalOptions="Fill"
                            Margin="10,5"
                            TextColor="Black"
                   
                   Placeholder="Username"
                PlaceholderColor="Gray"
                />


                            <Frame CornerRadius="20"  Grid.Row="5"  Margin="0,5"/>
                            <Entry
                               FontSize="16"
                            Grid.Row="5"
                            x:Name="password"
                            HorizontalOptions="Fill"
                            Margin="10,5"
                            TextColor="Black"
                    Placeholder="Password"
                PlaceholderColor="Gray"
                  
                />


                            <StackLayout Orientation="Horizontal"      Grid.Row="6">
                                <Label Text="Allow Access" TextColor="Black"  FontSize="16" HorizontalOptions="Center" VerticalOptions="Center" Margin="15,5"/>
                                <Switch
                           
                       ThumbColor="Black"
                                OnColor="White"
                            x:Name="appaccess"
                            HorizontalOptions="Center"
                            VerticalOptions="Center"
                            Margin="40,0"
                  
                />
                            </StackLayout>
                        </Grid>
                    </Frame>
                  

                <Button   CornerRadius="50" Text="Submit" FontSize="Medium" BackgroundColor="White" TextColor="Black"  FontFamily="audiofont" x:Name="save" HeightRequest="60" WidthRequest="140" HorizontalOptions="Center"  Margin="0,-85" />
            </StackLayout>

            <Frame CornerRadius="50" HeightRequest="100" WidthRequest="100" HorizontalOptions="Center" VerticalOptions="Start"  Padding="-2"  BorderColor="White"  Margin="20,5,20,0">
                    <Image HeightRequest="150" WidthRequest="150" x:Name="userprofile"  HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"  Source="grass.png"/>
                </Frame>
            </Grid>

        </StackLayout>
    </ScrollView>
</ContentPage.Content>