In my ViewModel
I have an ObservableCollection
of Person
objects (that implement INotifyPropertyChanged
) and a SelectedPerson
property. These are bound to a ListBox in my view.
There is also the following Prism DelegateCommand in my ViewModel:
Private DelegateCommand _myCommand = New DelegateCommand(CanExecute)
Public DelegateCommand MyCommand {get {return _myCommand;}}
Private Bool CanExecute()
{
Return (SelectedPerson.Age > 40);
}
What is the most elegant way of calling MyCommand.RaiseCanExecuteChanged whenever the SelectedPerson
changes and whenever the SelectedPerson
's age changes?
Adding and removing property changed handlers in the SelectedPerson
's setter seems a bit messy to me.