滚动没有发生

时间:2018-06-01 08:58:02

标签: c# xamarin xamarin.forms

我正在使用Visual Studio 2017开发一个Xamarin Forms项目。我需要使用滚动来显示长文本,所以我实现了以下代码,但它没有显示所有内容,它显示了部分内容而不是滚动,只有在标签的高度内显示文字。这对于Android和IOS都不起作用。如果我删除HeightRequest="350"它的滚动,但内容未显示

<Grid BackgroundColor="#0B738C">
    <Grid.ColumnDefinitions>
        <ColumnDefinition></ColumnDefinition>
    </Grid.ColumnDefinitions>

    <Grid.RowDefinitions>
        <RowDefinition Height="25"></RowDefinition>
        <!--bg-->
        <RowDefinition Height="20"></RowDefinition>
        <!--brand-->
        <RowDefinition Height="30"></RowDefinition>
        <!--Lable Agreement-->
        <RowDefinition Height="auto"></RowDefinition>
        <RowDefinition Height="40"></RowDefinition>
        <!--Text Agreement-->

        <!--checkox-->
        <RowDefinition Height="50"></RowDefinition>
        <!--I agree Button-->
        <RowDefinition Height="25"></RowDefinition>
    </Grid.RowDefinitions>

    <Image 
        Grid.Row="0" 
        Grid.Column="0" 
        Source="{local:ImageResource bg.jpg}" 
        Aspect="Fill" 
        Grid.ColumnSpan="1" Grid.RowSpan="12" x:Name="bgImage" />

    <Image 
        Grid.Row="1" 
        Grid.Column="0" 
        Source="{local:ImageResource brand.png}" 
        Aspect="Fill" 
        Scale="1.5"
        HorizontalOptions="Center"
        VerticalOptions="Center"
        Grid.ColumnSpan="1" Grid.RowSpan="1" x:Name="imageBrand" >
    </Image>

    <Label 
        x:Name="labelAgreement"
        IsVisible="True"
        Grid.Row="2" 
        Grid.Column="0" 
        Grid.RowSpan="2"
        HorizontalOptions="Center"
        Text="Software License and Agreement"
        TextColor="WhiteSmoke"
        FontFamily="Open Sans"
        Margin="10"
        FontSize="16" />

    <ScrollView Grid.Row="3" Grid.Column="0" >
        <StackLayout >
            <Label             
        x:Name="txtAgreement"
        HorizontalOptions="Center"
        VerticalOptions="Fill"
        HorizontalTextAlignment="Start"
        WidthRequest="300"
        HeightRequest="350"
        TextColor="Black"
        FontFamily="Open Sans"
        FontSize="10"
        FontAttributes="None"
        BackgroundColor="White"
        IsVisible="True"/>
        </StackLayout>
    </ScrollView>

    <Switch  

        x:Name="checkAgree"
        Scale="0.70"
        Grid.Row="4" Grid.Column="0" 
        Margin="15,0,10,5"
        HorizontalOptions="Start"
        Toggled="Handle_Toggled"></Switch>

    <Label      
        Grid.Row="4" Grid.Column="0" 
        HorizontalTextAlignment="Start"  
        VerticalTextAlignment="Center"
        HorizontalOptions="Start"
        TextColor="#FFFFFF"
        FontFamily="Open Sans"
        FontSize="14" 
        FontAttributes="Bold"
        Text="Agree to the above terms and conditions" 
        Margin="80,0,0,10"/>



    <Button 
        Margin="0,0,0,0"
        Grid.Row="5"
        Grid.Column="0"
        x:Name="buttonAgree"
        Text="Continue"
        HorizontalOptions="Center"
        VerticalOptions="CenterAndExpand"
        IsVisible="True"
        BackgroundColor="#1B9170"
        TextColor="#FFFFFF"
        FontFamily="Open Sans"
        FontSize="18"
        FontAttributes="Bold"
        WidthRequest="140"
        IsEnabled="False"
        Clicked="HandleAgree_Clicked"/>

    <Label 
        Grid.Row="5" 
        Grid.Column="0" 
        x:Name="labelError"
        Text=""
        Font="Large"
        HorizontalOptions="Center"
        VerticalOptions="CenterAndExpand"
        IsVisible="false"/>

</Grid>

1 个答案:

答案 0 :(得分:0)

您需要将HeightRequest提供给ScrollView。

    <ScrollView Grid.Row="3" Grid.Column="0" HeightRequest="250">
    <StackLayout >
        <Label             
    x:Name="txtAgreement"
    HorizontalOptions="Center"
    VerticalOptions="Fill"
    HorizontalTextAlignment="Start"
    WidthRequest="300"
    HeightRequest="350"
    TextColor="Black"
    FontFamily="Open Sans"
    FontSize="10"
    FontAttributes="None"
    BackgroundColor="White"
    IsVisible="True"/>
    </StackLayout>
</ScrollView>