views:

409

answers:

0

You can refer to this question for background/explanation of what the context to my problem is.

Basically, I have a WPF DataGrid bound to an ObservableCollection of an IEditableObject object. In a custom DataTemplate, for one of my columns that involves a flag enum property, I have constructed an Expander whose content is a bunch of checkboxes. I have verified that the checkboxes are correctly bound to my flag enum property and modify it appropriately.

Since this is a custom column which appears to be complicated, the BeginEdit/EndEdit/CancelEdit methods of the IEditableObject are never called. I suppose this means that the BeginEdit, CommitEdit and CancelEdit events of the DataGrid are never fired. I have verified that in all other columns, the IEditableObject and DataGrid interact as expected.

I need the DataGrid to be signaled for an edit when a checkbox is clicked in the flagged enum collection.

What I've Tried:

On the Expander.Expanded event, fire the DataGrid.BeginEdit event. On the Expander.Collapsed event, fire the DataGrid.CancelEdit event. On all of the Checkbox.Checked or Checkbox.Unchecked events, fire the DataGrid.CommitEdit event followed by the DataGrid.BeginEdit.

I thought by doing this that whenever the Expander is expanded, it will be in edit mode, each checkbox toggle will commit the edit and re-fire the BeginEdit (to keep the state the same) and when the DataGrid is collapsed, the edit will be cancelled.

However, upon trying this and debugging it, every time I click the toggle button to expand the DataGrid, a BeginEdit followed by an EndEdit is called in my IEditableObject class, and the expander does not expand. When I click it a second time, it expands with no events being fired. I'm not sure why this happens.

Any solutions/insight will be awesome. I can provide extracts of my code if you guys need to understand it better. Cheers.