Search code examples
silverlightsilverlight-4.0wcf-ria-servicesdataform

How to programatically detect if a DataForm is in edit mode


I'm using a DataForm in Silverlight 4. Several DataForms, actually, and they share a common RIA Services context. Here's the problem I'm having...

If I start editing a DataField in one of the DataForms, then click on a button that calls Context.SubmitChanges(), I get the following error:

�Entity 'foo' is currently being edited and has uncommitted changes. 
  A call to BeginEdit must be followed by a call to EndEdit or CancelEdit 
  before changes can be submitted.� 

Note that the "Submit Changes" button is external to the DataForms and applies to the RIA Services context that is shared between the DataForms (which are each in separate tabs of a tab control).

I'd like to be able to avoid this problem by detecting, in code, when a DataForm is in editing mode. When I'm in debug mode, I can see that the DataForm has properties such as IsEditing and CanCancelEdit that indicate that it is in editing mode, but these properties do not seem to be available for use in my code.

Any ideas?


Solution

  • Since none of the available properties provided the information I needed, I ended up creating my own private field (in the UserControl that contains the DataForm) called _isEditing which is initialized to "false". In the DataForm.BeginningEdit event handler I set it to "true" and in the DataForm.EditEnded event handler I set it to "false". I then created a read-only public property called IsEditing to make the value available externally.