Hello guys,
I tried to figure out how could I update my ListView after editing an already existed item. I found the following solutions:
https://developer.xamarin.com/samples/xamarin-forms/Todo/
and
https://github.com/conceptdev/xamarin-forms-samples/tree/master/TodoMvvm
More than less they are using the same tactic with a different way.
My questions is: do I need always to repopulate the listview after a change or after adding a new item?
Thanks in advance
@NikosG
Well... That logic of cancel and rollback isn't Xamarin specific. Its something we as developers have had to handle for years.
The general logic is that when the user is making an update they aren't doing it to the live data, but to a copy of that data.
So you make a copy of the live data then present some sort of editing UI with the copied data.
If they hit the [Cancel] button then just close the editing UI: No harm no foul.
If they hit the [Accept] button then replace the live data with the edited data.
Answers
Disclaimer: I only took a 60 second glance to confirm a suspicion.
It looks like you are honoring
INotificationPropertyChanged
- but notINotifyCollectionChanged
.So when you assign a complete new collection to the collection property, that raises an event.
But if an element WITHIN the collection changes there is no event, and thus your UI does not update automatically.
If you handle the CollectionChanged event as well, then your UI would hear the element within the collection change and update automatically: You would't have to reload programmatically.
My base levels usually look like this so code can be aware of all the really common needs:
@ClintStLaurent thank you very much. Actually that was what I really forgot to implement. But what if the user decide after all these changes just to cancel and rollback?
I mean could you please help me further as long as I am new with Xamarin.
And I just take a look... The INotifyCollectionChanged is only if a new item will be added or an old will be removed. What happens onEdit of an existed item?
@NikosG
Well... That logic of cancel and rollback isn't Xamarin specific. Its something we as developers have had to handle for years.
The general logic is that when the user is making an update they aren't doing it to the live data, but to a copy of that data.
So you make a copy of the live data then present some sort of editing UI with the copied data.
If they hit the [Cancel] button then just close the editing UI: No harm no foul.
If they hit the [Accept] button then replace the live data with the edited data.