Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Tracking Changes in Object State

Posted on 2012-03-22
1
Medium Priority
?
498 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 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
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 video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

610 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