Monday, April 11, 2011

How can I easily revert changes on a DataBound form?

If I have a form with controls DataBound to an instance variable object, is there a way to do revert changes that the user made, possibly by doing something like:

myLocalObject = DataLayer.GetCurrentState();

and have the form's controls (bound to myLocalObject) automatically pick up the changes?

Thanks!

From stackoverflow
  • Take a look into the IEditableObject interface.

    HTH, Kent

  • I've found that the following does the trick:

    var myLocalObject = DataLayer.GetCurrentState();
    LayoutRoot.DataContext = null;
    LayoutRoot.DataContext = myLocalObject;
    

    For some reason, if I don't set DataContext to null, my bound controls don't pick up the changes when changes are reverted.

0 comments:

Post a Comment