Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms ScrollView with long text

I have problem with putting long text into Label which is enclosed in ScrollView in Xamarin.Forms

I have something like this:

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="*"/>
    <RowDefinition Height="Auto"/>
  </Grid.RowDefinitions>
    <ScrollView Grid.Row="0">
        <customControls:Label x:Name="Text" />
    </ScrollView>
    <StackLayout Grid.Row="1">
        <Button Text="Cancel" Command="{Binding CancelCommand}" HorizontalOptions="Start" VerticalOptions="Center"></Button>
        <Button Text="Accept" Command="{Binding ShowSignatureCommand}" HorizontalOptions="End" VerticalOptions="Center" />
    </StackLayout>
</Grid>

And result is:

At beginning

It seems, that ScrollViewer does not hide stuff, which does not fit in it.

I have also tried with StackLayout, but same result.

How should I handle that?

like image 407
Tomasz Avatar asked Feb 01 '26 18:02

Tomasz


1 Answers

As I know it might happens when if you not define columns inside Grid. There are lots of way to do what you want:

With using Grid:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="70"/>
        <ColumnDefinition Width="70"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

    <ScrollView Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4">
        <yourControl/>
    </ScrollView>

    <Button Grid.Row="1" Grid.Column="1" Text="Ok" />
    <Button Grid.Row="1" Grid.Column="2" Text="Cancel" />
</Grid>

With using StackLayout:

<StackLayout>
    <ScrollView VerticalOptions="Fill">
        <yourViewController/>
    </ScrollView>

    <StackLayout HorizontalOptions="Center" Orientation="Horizontal" Spacing="5">
        <Button Text="Ok"/>
        <Button Text="Cancel"/>
    </StackLayout>
</StackLayout>
like image 71
eakgul Avatar answered Feb 04 '26 15:02

eakgul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!