MAUI:Refreshview 内的 Listview 完全伸展并滚动整个 UI

问题描述 投票:0回答:1

带有标签、搜索栏、按钮和列表视图的 UI 垂直布局。这个 UI 可以在没有 Refreshview 的情况下完美呈现,并且我可以滚动列表中的项目。但是,当这些控件放置在 Refreshview 中以执行 pulltorefresh 时,listview 会完全拉伸,并且整个 UI 会滚动,而不是列表项。将 heightRequest 属性设置为 listview 再次完美运行。但是我们不能将 Heightrequest 设置为 listview,因为我们有不同分辨率的各种设备。

Refreshview 中的类似代码结构在 Xamarin 中完美运行,但在 MAUI(所有平台)中面临问题。

有人可以选择解决这个问题吗?

代码片段:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiApp1.MainPage"
             xmlns:ViewCells="clr-namespace:MauiApp1">
<RefreshView>
<ScrollView VerticalOptions="Fill" >
<Grid RowDefinitions="Auto, Auto, *" ColumnDefinitions="*" VerticalOptions="Fill">
<Label Grid.Row="0" Grid.Column="0" Text="Search Items"  />
<SearchBar Grid.Row="1" Grid.Column="0" />
<ListView  RowHeight="30" Grid.Row="2" Grid.Column="0" ItemsSource="{Binding listItems}" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<HorizontalStackLayout >
<Label Text="{Binding name}"  />
</HorizontalStackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</ScrollView>
</RefreshView>
</ContentPage>
listview scrollview maui pull-to-refresh
1个回答
0
投票

ListView还支持上拉刷新功能,可以为ListView的

RefreshCommand
IsRefreshing
属性设置刷新事件,如以下代码:

<ListView ItemsSource="{Binding listItems}"
      IsPullToRefreshEnabled="true"
      RefreshCommand="{Binding RefreshCommand}"
      IsRefreshing="{Binding IsRefreshing}">
<ListView.ItemTemplate>
    <DataTemplate>
        <ViewCell>
            ...
        </ViewCell>
    </DataTemplate>
</ListView.ItemTemplate>

更多详情可以参考拉动刷新

© www.soinside.com 2019 - 2024. All rights reserved.