【问题标题】:Xamarin.Forms (iOS) - Listview it's being cutXamarin.Forms (iOS) - Listview 它正在被削减
【发布时间】:2026-01-03 04:15:01
【问题描述】:

我有一个 ListView,其中包含在我的 Xamarin.Forms 应用程序中用作菜单的图像。这是视图:

最后一项只是稍微超出屏幕,因此 ListView 需要向下滚动才能到达菜单的末尾。第一次呈现视图时,它会毫无问题地结束。然后,当我导航然后返回此视图时,我再也无法到达终点。

您可以在此处找到实时示例:

https://media.giphy.com/media/vvWQATVNlQ5ztX7New/giphy.gif

这是我的 XAML 代码:

<StackLayout>

    <ListView 
        x:Name="sampleListView"
        ItemsSource="{Binding MyList}"
        SeparatorVisibility="None"
        SeparatorColor="Transparent"
        ItemSelected="OnItemSelected"
        HasUnevenRows="true">

        <ListView.Margin>
            <OnPlatform x:TypeArguments="Thickness"
                  iOS="0,2,0,0"
                  Android="0,0,0,2" 
            />
        </ListView.Margin>

        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>                                  

                    <Grid BackgroundColor="#EFEFEF">

                        <ffimageloading:CachedImage                         
                            FadeAnimationEnabled="true" 
                            Source="{ Binding ImageNavigation }"
                            VerticalOptions="StartAndExpand"
                            Aspect="AspectFill"
                            HeightRequest="{Binding RowSizeMainMenu}"
                        />

                    </Grid>

                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>

    </ListView>

</StackLayout>

我们将不胜感激。

注意:这在 Android 中运行正常,该问题仅在 iOS 中可见。

【问题讨论】:

  • 你为什么不使用网格?
  • 尝试使用用户grid而不是stacklayout
  • 如果去掉listview周围的stacklayout,有效果吗?
  • 我认为这仍然是 xamarin 中的错误尝试使用 CachingStrategy="RecycleElement"
  • @AbdullahTahan,成功了。我可以接受你的问题是正确的,把它写下来。谢谢!

标签: listview xamarin.forms xamarin.ios


【解决方案1】:

我认为这仍然是 xamarin 中的错误尝试使用 CachingStrategy="RecycleElement"

【讨论】:

    【解决方案2】:

    设置您的主要StackLayout的以下属性

    VerticalOptions="FillAndExpand"

    【讨论】: