locked
How to prevent WPF two-way bindings to entities from forcing updates being submitted to the server RRS feed

  • Question

  • I have a WPF client that uses a WCF data service to load and entity object from a server. The entity object's properties are then displayed/edited using WPF bindings (e.g. TextBox with Text property bound to the entity object's property).

    When the user closes the window or navigates away, then DataServiceContext.SaveChanges() is called to submit any updates to the server. (There is no save button by intention). The DataServiceContext would look at all tracked entities and submit updates for the ones in state modified.

    However, what I am seeing is that when the tracked entity is bound to WPF controls using two-way binding, the entity is always considered to be modified. The client therefore always forces an update on the server, even if nothing was changed.

    What I suspect is that the WPF binding will submit its content back to the object (unchanged or not) by calling the setter. The setter unconditionally triggers INotifyPropertyChanged (regardless of whether the value has actually changed) and the DataServiceContext considers the object as modified.

    How can I prevent this? I would expect that updates are committed to the server only if the object has actually been changed.

    I do not want to implement my own dirty checking and conditionally call SaveChanges or not. If there are multiple entity objects tracked and bound, then this won't work anyway.

    I also do not want to change the auto-generated client side entity classes to detect and ignore bogus setter calls. This would be a lot of places and breaks upon updating the service reference.

    Any help would be greatly appreciated.

    J.-

    Tuesday, November 6, 2012 12:35 PM