-1

I am working at WPF application which manages datas for a Hospital, it is a classical Software Manager. My problem is the follwing:

When I open a window with contains Texbox, Combo or Grids I could change datas, save and close, but if the user closes it without save I will lose my changes. The common pattern I follow is check for any content ui element if its value was modified but that means to check any window in my application and write so much code. The question is, there is a way in WPF to know if ui element value was changed writring the code just once in generic class to inherits or in a static class?

Properly I mean if there is a native way which is built in in WPF, at moment the only way I keep in mind is find all of type control which can contains datas, attach "change event" and check if save is clicked before quit the window..

There any best practice to do it?

thanks

  • 1
    WPF does not have a change tracker. Best practice is to use MVVM and some kind of change tracking pattern or Unit of Work. (To put it another way, a TextBox has no notion of what the value 'was before') – Troels Larsen Jul 23 '14 at 13:00
  • You can probably use an XamlWriter as shown here: http://msdn.microsoft.com/en-us/library/system.windows.markup.xamlwriter.aspx – o_weisman Jul 23 '14 at 13:27

1 Answers1

1

First thing, if you are not using MVVM then start using it now. Second follow this link which show how you can use IChangeTracking to track the changes.

Community
  • 1
  • 1
Nitin Joshi
  • 1,606
  • 1
  • 14
  • 15