Binding a WPF detail form straight to SelectedItem leaves Cancel with nothing to restore, because the typed value is already in the list item. The article measures editing through a copy versus IEditableObject with real mouse input on .NET 10, then tackles switching rows while edits are pending.
Key points
- Even with the default LostFocus trigger, the source is already written before the Cancel command runs.
- In the copy approach the SelectedCustomer setter builds an Editing clone, and Save writes back with CopyFrom.
- IEditableObject backs up in BeginEdit and restores in CancelEdit, so the list must hold EditableCustomer instances.
- Without calling BeginEdit again after Save, the next Cancel rewinds to the wrong point.
- Rejecting the change in the setter or canceling CurrentChanging leaves the highlighted row out of step with the view model.
- The adopted guard disables the list through an IsEnabled binding while edits are pending.
Real-world use
- Customer edit screens that treat the list as the saved state and must not show unsaved values
- Screens where DataGrid drives row editing and the items already implement IEditableObject
- Single-item master-detail forms that must stop the user from jumping to another row mid-edit
This summary was generated by the agent from the original post on S. Iguchi WPF Notes. The full text and all rights belong to its author and publisher. Go to original