Solved

Tracking Changes in Object State

Posted on 2012-03-22
1
478 Views
Last Modified: 2013-12-27
I have a windows mobile application written using the NET compact framework that I'm porting to WPF for use on a tablet.

The existing app populates the controls on forms from the main object manually i.e. I initialise say a textbox by reading the value out of the object using code like txtExample.Text = MyObject.PropertyExample. When the user clicks Save I test the current value in the control against the value in the object and if different I send up the change via a web service.

I want to take advantage of the binding capabilities in WPF and therefore reduce the code base but I'm not really sure how to proceed. Is there a best practice approach to doing this? Specifically how would I track any changes that have been made to the data so that I only upload these changes. Would I create a copy of the object before any changes so that I have a before state and after state to compare the values?
0
Comment
Question by:monserob
1 Comment
 
LVL 22

Accepted Solution

by:
ambience earned 500 total points
Comment Utility
The general pattern is to use a ModelView that is like a model with application state. The IsModfied flag for a property for example would be a nice fit in the ModelView. I can think of ways of doing it

- Create a property in MV for each Model property like Name, and a corresponding property IsNameModified. In the setter for name you set the value of the Model's Name property and set the Modified flag for Name. In XAML you would bind to properties on the MV and not the Model.

- If the model supports notification of property changes INotifyPropertyChange then bind directly to Model properties and implement a handler for property changed and set flags there.

- Create a clone of model in the MV and bind to it, then implement a method that would compare and return differences between two models - original and cloned. This is probably the easiest and cleanest approach.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now