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. Howe开发者_运维知识库ver 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?
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.
精彩评论