Ingó Vals
Ingó Vals

Reputation: 4898

WPF MVVM: Notify property changed one property everytime some other property is changed

I have a ViewModelBase class where I define RaisePropertyChanged method for the INotifyPropertyChanged interface. Most MVVM people are pretty familiar with this.

I also have a Validating ViewModel that inherits from ViewModelBase. It implements a interface and some methods to validate it's properties. It has a IsValid property the is only a getter who checks if there are any rule violations. However if I would wan't to bind to this property in the Views it would have to get updated at some time. This would basicly be everytime some other property is changed, or at least properties that I validate against. One simple solution would be to just Notify IsValid inside the RaisePropertyChanged method but it is defined in ViewModelBase where IsValid hasn't been defined.

Would any of you have a good solution for this dilemma?

Upvotes: 1

Views: 1317

Answers (1)

devdigital
devdigital

Reputation: 34349

If you are following the standard event handling pattern, your RaisePropertyChanged method will be marked as virtual (it should probably be a protected virtual method), so you'll be able to override that method in your validating view model, call the base implementation, and then invoke the PropertyChanged event for the IsValid property.

I'm not quite sure what you are doing, but if it is general validation, you would be better off using a framework such as DataAnnotations.

Upvotes: 3

Related Questions