hyuckkim
hyuckkim

Reputation: 69

Maui ScrollView - Scrollbar length not updating when content dynamically changed

I tried this content with TwoWay mode.
I used ObservableCollection, when I modify the content is updated, but the scroll length is not updated.

![scrollview content is too long

Right Scrollbar is too long.
How can I update the scrollbar length?

<ScrollView BackgroundColor="LightGray" x:Name="InfoStack">
        <StackLayout
            BindableLayout.ItemsSource="{Binding Source={x:Static local:InfoHelpers.Ints}, Mode=TwoWay}">
            <BindableLayout.ItemTemplate>
                <DataTemplate>
                    <.../>
                </DataTemplate>
            </BindableLayout.ItemTemplate>
        </StackLayout>
    </ScrollView>

Upvotes: 4

Views: 1679

Answers (2)

ToolmakerSteve
ToolmakerSteve

Reputation: 21223

After changing content, this might fix it:

(InfoStack as IView).InvalidateArrange();

UPDATE BASED ON COMMENT

Instead use:

(InfoStack as IView).InvalidateMeasure();

Upvotes: 2

ColeX
ColeX

Reputation: 14475

It behavior differently on different platforms .

I did test your code on Windows desktop , iOS and Android simulator .

The result is that it only works on Windows desktop, ScrollView does not expand dynamatically as expected on iOS and Android .

It seems like a potential issue , consider rainsing the issue on github :https://github.com/dotnet/maui/issues .

Workaround

Use CollectionView instead of ScrollView.

<CollectionView ItemsSource="{Binding Source={x:Static local:InfoHelpers.Ints}, Mode=TwoWay}">
   <CollectionView.ItemTemplate>
      <DataTemplate>      
          <Label Text="{Binding .}" HeightRequest="40"/>             
      </DataTemplate>
   </CollectionView.ItemTemplate>
</CollectionView>

Upvotes: 1

Related Questions