Solved

Tracking Changes in Object State

Posted on 2012-03-22
1
485 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
ID: 37758629
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Let me explain this picture a little bit.  First, in case you haven't already guessed, you are looking at my 2 phones, an Android Samsung Galaxy S5 on the left and an iPhone 5 on the right.  They are on their respective cradles on my desk.  But, you…
In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

831 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