Reputation: 446
I'm using Prism in my Xamarin Forms application.
I'm Binding a Observable Collection to a List View and when I refresh the data the View Model Collection updates with the new data but the UI is not updated.
After a bit of research I found that the collection only updates when items are added or removed.
public async Task RefeshEvents()
{
try
{
IsLoading = false;
IsRefreshing = true;
Events = await _eventService.GetEvents();
IsRefreshing = false;
}
catch (Exception)
{
await
_pageDialogService.DisplayAlertAsync("Connection Error",
"We could not Connect to the internet please check your connection", "Ok");
IsRefreshing = false;
}
}
As you can see I am assigning a new List to the Collection.
private ObservableCollection<Event> _events;
public ObservableCollection<Event> Events
{
get { return this._events; }
set { SetProperty(ref _events, value); }
}
Is there a way for me to update the UI without having to manually manage the list?
Upvotes: 2
Views: 1982
Reputation: 10863
If Events
is the ObservableCollection
, you have to raise a NotifyProperty
for that property when you set it to a new value for the ui to update according to the new value, like any other property.
ObservableCollection
updates the ui automatically when you modify the collection (i.e. add or remove elements), but when you replace the whole collection, you don't modify the collection but a property of your view model.
Upvotes: 2