This is not a solution, merely a workaround. I've created an attached property for the datagrid that will be linked to a notifying bool property in the viewmodel. When flipping that bool, the editing mode of the datagrid is ended. In my code, I'm flipping that bool when the SelectedItem of the tabcontrol which contains the datagrid changes.
public class DataGridBehaviors
{
#region EndEditing Property
public static void SetEndEditing(DependencyObject obj, bool a)
{
obj.SetValue(EndEditingProperty, a);
}
public static bool GetEndEditing(DependencyObject obj)
{
return (bool) obj.GetValue(EndEditingProperty);
}
public static readonly DependencyProperty EndEditingProperty
= DependencyProperty.RegisterAttached(
"EndEditing",
typeof(bool),
typeof(DataGridBehaviors),
new PropertyMetadata(new PropertyChangedCallback(EndEditingChanged))
);
private static void EndEditingChanged(DependencyObject sender,
DependencyPropertyChangedEventArgs e)
{
var dg = sender as DataGrid;
if (null == dg) return;
dg.CancelEdit();
dg.CommitEdit();
}
#endregion
}