문제

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()?"

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top