EditLevel not incrementing

EditLevel not incrementing

Old forum URL: forums.lhotka.net/forums/t/6861.aspx


shawndewet posted on Tuesday, April 28, 2009

Using WPF, I have set my CSLA BusinessBase object as the DataContext  (as opposed to going via the CslaDataProvider), and the databinding is working to the extent that I can see the values of the properties showing up on the form in the text boxes as expected.

When I edit a value in a text box and tab off it, the appropriate property setter is hit (confirmed by the use of breakpoints) and the underlying value of the field is changed, and the object's IsDirty correctly returns True.

However, the problem is that the EditLevel of the object is still 0 (zero).  The effect of this is that calling CancelEdit does nothing.   According to page 279 of the VB 2008 book, BeginEdit (which does the stack copy, resulting in EditLevel being incremented) is called by DataBinding automatically.  So it seems to me that I am missing something in my implementation...does anybody have any idea what this missing piece may be?  It's no different (in concept) to what would do in Windows databinding, and there it is working fine.

RockfordLhotka replied on Tuesday, April 28, 2009

BeginEdit() is called automatically by data binding in Windows Forms. And it is called automatically (via the IEditableObject interface) in a WPF grid.

But outside a grid, WPF doesn't call IEditableObject at all, and it is your responsibility to manage the undo behaviors of the object.

The CslaDataProvider (with ManageObjectLifetime="true") does work with data binding to automatically call BeginEdit() - this is one of the benefits of using the CslaDataProvider.

shawndewet replied on Tuesday, April 28, 2009

Thanks Rocky.  I guess I should read the book finished, huh? ;-)

Could you please expand on what you mean by "in a WPF grid"? (I do presume you mean "grid" here as opposed to "datagrid").  All my databound controls are indeed inside a grid control.  Does this mean I should be setting the binding source on the grid control (as opposed to setting it on the usercontrol as I am currently doing)?

Copyright (c) Marimer LLC