xamarin 中的列表视图中的空视图

Empty view in list View in xamarin

我的 xamarin 应用程序中有一个列表视图,我需要添加一个选项,当列表为空时,在集合视图中我们有 <CollectionView.EmptyView> 但是当我搜索列表视图时没有选项对于它,它更复杂,所以,有没有快速修复的方法?它的标准解决方案是什么?

实际上,CollectionViewempty view.However, if you insist on using listivew to achieve empty view effect,you could use this package Syncfusion.Xamarin.SfListView.Just binding IsVisible property when the listview is empty like below,for more details please refer to this repo 更好的选择。

      <Grid>
        <Button x:Name="ItemSource" Grid.Row="0" 
                Text="Change ItemSource" 
                 HorizontalOptions="CenterAndExpand"
                 VerticalOptions="CenterAndExpand" 
                Command="{Binding ChangeItemsSource}"/>
        <Grid IsVisible="{Binding IsVisible}" Grid.Row="1">
            <Label x:Name="label"
                   Text = "No Items :(" />
        </Grid>
        <sync:SfListView x:Name="listView" Grid.Row="1" 
                         ItemsSource="{Binding ContactsInfo}"
                         IsVisible="{Binding Path=IsVisible, Converter={StaticResource visibilityConverter}}"
                         ItemSize="30">
            <sync:SfListView.ItemTemplate>
                <DataTemplate>
                    <Label Text="{Binding ContactName}"/>
                </DataTemplate>
            </sync:SfListView.ItemTemplate>
        </sync:SfListView>
    </Grid>

官方参考link:https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/collectionview/emptyview