Here's the excerpt from https://learn.microsoft.com/en-us/archive/blogs/vinsibal/5-random-gotchas-with-the-wpf-datagrid:
5.Data source items should implement IEditableObject to get transactional editing functionality.
If you are not familiar with IEditableObject, see this MSDN article which has a good explanation and code sample. The DataGrid has baked in functionality for transactional editing via the IEditableObject interface. When you begin editing a cell, the DataGrid gets into cell editing mode as well as row editing mode. What this means is that you can cancel/commit cells as well as cancel/commit rows. For example, I edit cell 0 and press tab to the next cell. Cell 0 is committed when pressing tab. I start typing in cell 1 and realize I want to cancel the operation. I press ‘Esc’ which reverts cell 1. I now realize I want to cancel the whole operation so I press ‘Esc’ again and now cell 0 is reverted back to its original value.
I get this same transactional behavior even without implementing IEditableObject. What am I missing?
public class Person {
public string FirstName { get; set; }
public string LastName { get; set; }
public string Description { get; set; }
}
People = new List<Person> {
new Person(){FirstName = "fname", LastName = "lname", Description = "description"}
};
<DataGrid ItemsSource="{Binding Path=People}" />