This question is locked. New answers and comments are not allowed.
The default behavior of a column when Esc is pressed (when in edit mode) appears to set DataMemberBinding back to the same textual value it was prior to the edit. Though this is appropriate at times, it is more often innappropriate when working with entites with navigation properties and I would like to know how to change this behavior.
Take the example of a collection of Customers, each with a navigation property of Contact. So the Customer has a property of ContactId which is a Contact object that has Name, Phone, etc. To show the Contact name in the grid one could do DataMemberBinding={Binding Contact.Name} (assuming the row context is the Customer). This looks fine, but of course if you try to edit this column you will be editing Contact.Name and not Customer.ContactId. So implement the CellEditingTemplate and make the edit template show whatever is appropriate to modify the Customer.ConactId which will in turn change Customer.Contact and reflect Customer.Contact.Name in column.
The problem comes when you want to hit Esc after having edited that column. It will revert Customer.Contact.Name back to the textual value it was prior to the edit - which is now technically a different Contact. So now you have two Contacts with the same name. It should, instead, set Customer.ContactId back to its previous value but of course it knows nothing of what the appropriate action should be.
If you define Contact.Name without a setter this causes the grid to not let you put the column in edit mode even though you have IsReadOnly=false and/or you have a CellEditTemplate defined. (this "feature" is rediculous).
If you set the Mode=OneWay for the DataMemberBinding the grid does not respect this and edits the value as it desires.
If you implement IEditableObject it still resets the value so I end up with the Contact.Name is changed, but the Customer resets properly. So every row that uses the changed Contact so the new Name.
So, how do I define what value should be reset when Esc is pressed? I do not want to have to define CellTemplates on every single column and customize the filter on ever column just so I can set the DataMemberBinding to {Binding ContactId}. Surely there is a way to define the behavior.
Assuming you want to show "Contact.Name", filter by "Contact.Name", but when Esc is pressed I want to reset "ContactId".
In my case if when I pressed Esc it could trigger a command and pass in the "UniqueName" or the column then I could do the reset myself.
I tried messing with a KeyboardCommandProvider but it does not truely expose all the commands its going to execute and therefore modifying them gives mixed results.
Take the example of a collection of Customers, each with a navigation property of Contact. So the Customer has a property of ContactId which is a Contact object that has Name, Phone, etc. To show the Contact name in the grid one could do DataMemberBinding={Binding Contact.Name} (assuming the row context is the Customer). This looks fine, but of course if you try to edit this column you will be editing Contact.Name and not Customer.ContactId. So implement the CellEditingTemplate and make the edit template show whatever is appropriate to modify the Customer.ConactId which will in turn change Customer.Contact and reflect Customer.Contact.Name in column.
The problem comes when you want to hit Esc after having edited that column. It will revert Customer.Contact.Name back to the textual value it was prior to the edit - which is now technically a different Contact. So now you have two Contacts with the same name. It should, instead, set Customer.ContactId back to its previous value but of course it knows nothing of what the appropriate action should be.
If you define Contact.Name without a setter this causes the grid to not let you put the column in edit mode even though you have IsReadOnly=false and/or you have a CellEditTemplate defined. (this "feature" is rediculous).
If you set the Mode=OneWay for the DataMemberBinding the grid does not respect this and edits the value as it desires.
If you implement IEditableObject it still resets the value so I end up with the Contact.Name is changed, but the Customer resets properly. So every row that uses the changed Contact so the new Name.
So, how do I define what value should be reset when Esc is pressed? I do not want to have to define CellTemplates on every single column and customize the filter on ever column just so I can set the DataMemberBinding to {Binding ContactId}. Surely there is a way to define the behavior.
Assuming you want to show "Contact.Name", filter by "Contact.Name", but when Esc is pressed I want to reset "ContactId".
In my case if when I pressed Esc it could trigger a command and pass in the "UniqueName" or the column then I could do the reset myself.
I tried messing with a KeyboardCommandProvider but it does not truely expose all the commands its going to execute and therefore modifying them gives mixed results.