xamarin.formsmvvmconstructorpage-refresh

Xamarin.Forms - Instantiate ViewModel Constructor everytime I open the page in AppShell


I have a page that has some collection views that contains data. Data can be removed while using the app. The problem is that when I delete an object from that is part of one of these collection view (I delete it in another page), once I return to the page it still show me the object. I don't know if a RefreshView could be helpful since I'm updating data on the constructor. What should I do?

public MyViewModel() {
   Profile = App.currentUser;
   User additionalData = JsonConvert.DeserializeObject<User>(Profile.AdditionalData);
   BorrowedBooks = additionalData.BorrowedBooks;
   Wishlist = additionalData.Wishlist; 
}

Solution

  • load your data in OnAppearing instead of in the constructor. Alternately, you can use MessagingCenter to send a message whenever an item is removed