Friday, May 6, 2011

File has been modified? Now to handle in WPF?

Hi,

What's the best way to tell my application that the file has been modified and that it should ask the user for a filename? Is there a class for that or do I write that all that logic by hand?

Thanks!

From stackoverflow
  • You'll need to handle that logic by hand. It's not too difficult if you've got a decent application architecture working for you. Just flip a Modified flag on your "file" object that gets serialized to disk whenever the object is mutated.

  • Another solution is something I've seen recently. If setting a modified flag on your 'file' object is difficult, you could always try saving to a memory stream and calculating a hash on it, and if the hash is different to the original version's hash, it has changed.

    It's not as elegant as setting a modified flag, but is much easier to retrofit.

    Steve the Plant : Another way is if your app has an undo/redo stack. Having at least one element in your undo stack means you've modified the scene. But it does require every action in the application be undoable.

0 comments:

Post a Comment