I have a listview and what I want to do is when I click on an item, a new page is launch with the details. On this page there will be a delete button, and if I press it, the element is deleted from the database and the page is popasync to go back to the list.
Then I need to update my listview, currently I made it work thanks to a messagingcenter but I don't know if it's the best solution.
This is how I launch my detailspage :
cardList.ItemTapped += async (sender, e) =>
{
await Navigation.PushAsync(new CardDetails((Card) e.Item, database));
};
This is my details page with the delete code :
var toolbarItem = new ToolbarItem
{
Name = "Supprimer",
Command = new Command(this.deleteAndReturn),
};
private void deleteAndReturn()
{
database.deleteCard(card);
Navigation.PopAsync();
MessagingCenter.Send<CardDetails>(this, "Delete");
}
On my listPage I update the view like that :
MessagingCenter.Subscribe<CardDetails>(this, "Delete", (sender) => {
cardList.ItemsSource = database.getCards();
});
Is it a good way to do that ? I already so that we can listen to event like "popped" but I don't know how to listen to it. I think the equivalent in android would be "OnActivityResult".