I have already asked this question on StackOverflow, EggHeadCafe and MSDN Discussions without any solutions. Here is a copy of my question. Please let me know if you would like supporting code to help understand the issue:
I have a DataGrid set-up with a custom template for columns. The grid is bound programmatically to an ObservableCollection<X> where X implements IEditableObject.
All the "simple"columns that I have bind correctly since they are all bound to string values in my object X. However, one of the properties of object X is a flagged enum property. Let's call it X.FlaggedEnum.
I have behavior working with X.FlaggedEnum such that that column in the DataGrid is a DataGridTemplateColumn with an Expander object. The expander content reveals a collection of checkboxes that turn on/off the appropriate flagged values of the enum using a
value converter. All that work beautifully and X.FlaggedEnum is the correct value when X.EndEdit() is called following a DataGrid edit event.
The issue here is that only editing the text cells fires the DataGrid editing events into the pipeline. Checking the checkboxes/expanding the expander/etc. do not fire the edit events and hence X.BeginEdit(), X.CancelEdit() and X.EndEdit() are never called.
Hence, only if another field is changed, after the flagged enum is modified, is the data stored into the database (this is what I do in EndEdit).
I have tried a variety of things including trying to fire the edit events of the DataGrid through DataGrid.BeginEdit(), DataGrid.CancelEdit() and DataGrid.CommitEdit(). However, it seems that every time I call BeginEdit (I do this in the Expander.Expanded event
handler), for some reason the EndEdit is called immediately on the IEditableObject interface
and the expander doesn't expand. No idea why that happens.
Anyone have any thoughts? This has been bugging me for a while now. I can code a hack-around that has a "Save" button on my expander that uses the current row to figure out the instance of X and call save manually, but I'd rather I use the existing
piping if it is possible.