I have seen three ways to bind a ListView, what is the good way, how to get the ListView refreshed?
1. non static:
XAML:
<ContentPage.BindingContext>
<viewModels:PositionsViewModel/>
</ContentPage.BindingContext>
<ListView x:Name="listView"
SeparatorVisibility="Default"
HasUnevenRows = "true"
ItemSelected="OnCelestialPositionSelected"
ItemsSource="{Binding Positions}">
<!-- ItemsSource="{x:Static viewModels:PositionsViewModel.Positions}" -->
Model:
public class PositionsViewModel : BaseViewModel
{
public List<Position> Positions { get; set; }
public PositionsViewModel()
{
Positions = App.PositionsSightsDB.GetPositionsAsync().Result;
Positions.Sort();
}
2. Static
XAML:
<ContentPage.BindingContext>
<viewModels:PositionsViewModel/>
</ContentPage.BindingContext>
<ListView x:Name="listView"
SeparatorVisibility="Default"
HasUnevenRows = "true"
ItemSelected="OnCelestialPositionSelected"
<!-- ItemsSource="{Binding Positions}"-->
ItemsSource="{x:Static viewModels:PositionsViewModel.Positions}" >
Model:
public class PositionsViewModel : BaseViewModel
{
public static List<Position> Positions { get; set; }
public PositionsViewModel()
{
Positions = App.PositionsSightsDB.GetPositionsAsync().Result;
Positions.Sort();
}
3. OnAppearing:
.xaml.cs
protected override async void OnAppearing()
{
base.OnAppearing();
listView.ItemsSource = await AlmicantaratXF.App.PositionsSightsDB.GetPositionsAsync();
}
I don't understand the difference between the 1. (non-static) and the 2. (Static). The list does not refresh: if I PushAsync a page, delete an item and PopAsync() the page which came over
With the 3rd solution, the list is refreshed but not sorted.
How to get a sorted and refreshed list?