I found a solution - but so your developers know, I think there is a bug with GetItemFromContainer() when insertion rows are involved.
The solution is to instead use ((Row) sender).DataContext
- When the Row is a normal DataRow, this will give the MyObject underlyingItem correctly.
- When the Row is an InsertionRow, and the InsertionRow is not currently being edited, this will give a DataTemplate object.
- When the Row is an InsertionRow, and the InsertionRow IS currently being edited, this will correctly give the MyObject underlyingItem that has been created but not yet comitted.
Note that whether an InsertionRow is currently being edited or not (i.e. whether or not the InsertionRow currently has an underlying item), GetItemFromContainer() will always return the DataTemplate of the InsertionRow, and I think that's a mistake.