I have a listview in my app and I created in my ViewModel a LoadListView () method;
When I call it through the constructor of my ViewModel, an ObservableCollection list is loaded and the binding is given in my view.
When I call the LoadListView () method with a one-button command, the LoadListView () method is called and the list is loaded, but it does not bind in my view.
Does anyone know why?
This is my listView
<ListView Grid.Row="2"
Grid.Column="1"
Grid.ColumnSpan="3"
ItemsSource="{Binding ListaIntervalos }"
HasUnevenRows="true">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Label Grid.Row="1" Grid.Column="0" Text="{Binding De}" FontSize="20" VerticalOptions="Start" TextColor="Black"/>
<Label Grid.Row="1" Grid.Column="1" Text="{Binding Ate}" FontSize="20" VerticalOptions="Start" TextColor="Black"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
And in my View Model this way
public ObservableCollection<Intervalo> ListaIntervalos { get; private set; } = new ObservableCollection<Intervalo>();
//Construtor
public VMBuscarSalto()
{
// Aqui funciona
this.CarregaIntervalos();
}
public Command BuscaSaltosCommand
{
get
{
return new Command(() => ExecuteBuscaSaltosCommand());
}
}
private void ExecuteBuscaSaltosCommand()
{
// Aqui a lista é carregada mas não dá o bind no listview
this.CarregaIntervalos();
}