简体   繁体   中英

Xamarin.Forms PullToRefresh not occuring when ListView is empty?

In Xamarin.Forms I have a simple ListView that is bound to a view model using MVVM.

  <ListView Grid.Row="1"
                     ItemsSource="{Binding ContactsGrouped}"
                     IsGroupingEnabled="true"
                     IsPullToRefreshEnabled="True"
                     RefreshCommand="{Binding RefreshCommand}"
                     IsRefreshing="{Binding IsRefreshing}"
                     GroupDisplayBinding="{Binding Key}"
                     GroupShortNameBinding="{Binding Key}"
                     BackgroundColor="Transparent"
                     SelectionMode="Single"
                     HasUnevenRows="true" 
                     SeparatorColor="#cccccc">
        <ListView.ItemTemplate>
            <cr:MyItemTemplate>
        </ListView.ItemTemplate>
    </ListView>

This is my xaml code, which works perfectly fine if the list has at least 1 item. By tapping and pulling down on the item, the list view refreshes fine, however tapping and pulling down outside of the item, the list does not cause PullToRefresh to occur. It's almost as if the ListView has transparent input but its items do not, thus allowing it to work.

Anything in the red in my example image shows the area where if I tap and drag down the activity indicator appears fine and the refresh happens. Tap and dragging anywhere in the green however causes the View to not refresh and the activity indicator to not appear. 例

I won't show my view model as the issue is with the View. I've also tried setting background color to red, checking if transparent was causing an issue, sadly that is not the case. Any ideas?

Try adding VerticalOptions="StartAndExpand".

<ListView Grid.Row="1"
    ItemsSource="{Binding ContactsGrouped}"
    IsGroupingEnabled="true"
    IsPullToRefreshEnabled="True"
    RefreshCommand="{Binding RefreshCommand}"
    IsRefreshing="{Binding IsRefreshing}"
    GroupDisplayBinding="{Binding Key}"
    GroupShortNameBinding="{Binding Key}"
    BackgroundColor="Transparent"
    SelectionMode="Single"
    HasUnevenRows="true" 
    SeparatorColor="#cccccc"
    VerticalOptions="StartAndExpand">
        <ListView.ItemTemplate>
            <cr:MyItemTemplate>
        </ListView.ItemTemplate>
</ListView>

This property tells the View how much space of your screen should it cover. If you don't add it then the View will just cover whatever the required length to display the data it needs.

I just reproduced your problem on my side. After some researching, I found it is known issue from Xamarin.forms 3.5.0 and it still exist in Latest stable 3.6.0.344457 .

The WorkAround is downgrade your Xamarin.forms version to 3.4.0 .

Also, I test it in the Latest prerelease 4.0.0.394984-pre10 and it works well. So, I believe this issue will be solved in the next release version.

You can follow this issue to check the process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM