Solved

Tracking Changes in Object State

Posted on 2012-03-22
1
491 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

730 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