mvvm - prismv2 - INotifyPropertyChanged

Posted by depictureboy on Stack Overflow See other posts from Stack Overflow or by depictureboy
Published on 2010-04-27T20:15:04Z Indexed on 2010/04/29 10:27 UTC
Read the original article Hit count: 502

Filed under:
|
|

Since this is so long and prolapsed and really doesnt ask a coherent question:

1: what is the proper way to implement subproperties of a primary object in a viewmodel?

2: Has anyone found a way to fix the delegatecommand.RaiseCanExecuteChanged issue? or do I need to fix it myself until MS does?

For the rest of the story...continue on.

In my viewmodel i have a doctor object property that is tied to my Model.Doctor, which is an EF POCO object. I have onPropertyChanged("Doctor") in the setter as such:

       Private Property Doctor() As Model.Doctor
            Get
                Return _objDoctor
            End Get
            Set(ByVal Value As Model.Doctor)
                _objDoctor = Value
                OnPropertyChanged("Doctor")
            End Set
        End Property

The only time OnPropertyChanged fires if the WHOLE object changes. This wouldnt be a problem except that I need to know when the properties of doctor changes, so that I can enable other controls on my form(save button for example). I have tried to implement it in this way:

Public Property FirstName() As String
        Get
            Return _objDoctor.FirstName
        End Get
        Set(ByVal Value As String)
            _objDoctor.FirstName = Value
            OnPropertyChanged("Doctor")
        End Set
    End Property

this is taken from the XAMLPowerToys controls from Karl Shifflet, so i have to assume that its correct. But for the life of me I cant get it to work.

I have included PRISM in here because I am using a unity container to instantiate my view and it IS a singleton. I am getting change notification to the viewmodel via eventaggregator that then populates Doctor with the new value. The reason I am doing all this is because of PRISM's DelegateCommand. So maybe that is my real issue.

It appears that there is a bug in DelegateCommand that does not fire the RaiseCanExecuteChanged method on the commands that implement it and therefore needs to be fired manually. I have the code for that in my onPropertyChangedEventHandler. Of course this isnt implemented through the ICommand interface either so I have to break and make my properties DelegateCommand(of X) so that I have access to RaiseCanExecuteChanged of each command.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about mvvm