Question

In my viewmodel, there is a property CurrentObject of the type SomeDomainType which is serializeable.

There is a form to edit its properties, and one of the buttons is "Commit Changes", databound to the ICommand CommitChangesCommand.

Now I expect this button to be active (via CanCommitChangesCommand(), properly wired with Josh Smith's RelayCommand) only when the object has been modified, that is, the object is "dirty".

Saying it again, what I want to ask is:

"How can I mark an object as dirty so that I could have a private bool ThatPropertyIsDirty() method to check that inside some CanExecute()?"

Était-ce utile?

La solution

From the sound of it:

  1. Add a IsDirty property onto your SomeDomainType
  2. In the setter of IsDirty raise the NotifyPropertyChanged event for IsDirty
  3. In all of the properties on your SomeDomainType that you change to make the object considered Dirty, in their setters, set IsDirty to true

This is presuming your SomeDomainType implements the INotifyPropertyChanged interface. If not, create a wrapper class around the SomeDomainType that does, and make the above changes to that wrapper.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top