An object-oriented programming language developed by Microsoft that can be used in .NET.
Hello @RogerSchlueter-7899 ,
The issue you are experiencing is due to how reference types (like classes) work in .NET. When you click the Cancel button the first time, you are executing this line: CurrentPerson = OriginalPerson
Instead of copying the original values back, this line makes CurrentPerson point to the exact same object in memory as OriginalPerson. This means that when the user makes additional edits after the first cancel, they are now modifying the OriginalPerson object directly. The original state is permanently overwritten, so clicking Cancel a second time does nothing because the "backup" is already modified.
To fix this, you need to assign a new copy of OriginalPerson back to CurrentPerson when canceling, just like you did when initially selecting a person.
Additionally, your OnPropertyChanged event should notify the UI that CurrentPerson has changed, rather than OriginalPerson, assuming your UI is bound to CurrentPerson.
I suggest trying this implementation for your cancel button:
Private Sub CancelChanges(sender As Object, e As RoutedEventArgs) Handles btnCancel.Click
' 1. Revert by creating a fresh copy from the original object
CurrentPerson = OriginalPerson.ShallowCopy()
' 2. Notify the UI that CurrentPerson has been updated
OnPropertyChanged(NameOf(CurrentPerson))
End Sub
By using .ShallowCopy() in the cancel method, OriginalPerson will remain safely unmodified in memory regardless of how many times the user edits and cancels.
Hope this helps! Let me know if you have any further questions. If you found my response helpful or informative, I would greatly appreciate it if you could follow this guide for your confirmation.
Thank you.