How can I easily revert changes on a DataBound form?
-
03-07-2019 - |
Question
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!
Solution 2
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.
OTHER TIPS
Take a look into the IEditableObject
interface.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow