I have a list view in my xamarin app and I need to put an option that when the list is empty, in the collection view we have <CollectionView.EmptyView>
but when I search for list view there is no option for it and it's more complex, so, there is a quick fix or not? and what is the there standard solution for it ?
CodePudding user response:
Actually,CollectionView
is a better choice for empty 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>
Official reference link:https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/collectionview/emptyview