Solved

Tracking Changes in Object State

Posted on 2012-03-22
1
487 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
I recently asked a question (http://www.experts-exchange.com/Programming/Smartphones/Android/Q_28684946.html) about Computer Inventory applications for Mobile Devices.  I was specifically interested in an app I could use on my android phone.  The be…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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