首页 > 解决方案 > Xamarin:元素在 ScrollViewer 中被截断/未呈现

问题描述

我有以下情况。

<ScrollView BackgroundColor="DeepPink">
    ...
    <Grid HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
        <ContentView Opacity="{Binding  ViewProvider.IsCancelling, Converter={StaticResource BoolToOpacityConverter}}" Content="{Binding ViewProvider.CurrentView}"/>
    </Grid>
    ...
</ScrollView>

内容视图包含多个元素,其中一个是带有 BindableLayout.ItemsSource 的 StackLayout

<StackLayout BindableLayout.ItemsSource="{Binding Rings}" Margin="12,0,0,0">
    <BindableLayout.ItemTemplate>
        <DataTemplate>
            ...
        </DataTemplate>
    </BindableLayout.ItemTemplate>
</StackLayout>

在视图打开时,将通过不同的操作添加环。一旦发生这种情况,ScrollViewer 的高度就会增加,但下面的部分会被截断或只是不渲染。(它减少了环使用的高度 - 我猜是因为 Grid 没有调整大小?但为什么呢?)

Xamarin 的 ScrollViewer 问题

我尝试在添加环后调用InvalidateMeasure()ForceLayout()但没有任何更改。有任何想法吗?

编辑

按照评论中的要求,我在 github 上上传了一个简单的演示来重现这个问题。 https://github.com/Valronicon/ScrollViewerIssue

谢谢!

编辑 2

我可以通过将 ScrollViewer 包装在一个额外的网格中来解决这个问题。不知道为什么它有效,但它有效......

标签: c#xamarinxamarin.formsxamarin.androidscrollviewer

解决方案


推荐阅读