views:

34

answers:

1

This is my ViewModel Code: vb:

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

    Public Property AddDate() As Nullable(Of DateTime)
        Get
            Return _objDoctor.AddDate
        End Get
        Set(ByVal Value As Nullable(Of DateTime))
            _objDoctor.AddDate = Value
            OnPropertyChanged("Doctor")
        End Set
    End Property

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

    Public Property ChangeDate() As Nullable(Of DateTime)
        Get
            Return _objDoctor.ChangeDate
        End Get
        Set(ByVal Value As Nullable(Of DateTime))
            _objDoctor.ChangeDate = Value
            OnPropertyChanged("Doctor")
        End Set
    End Property

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

    Public Property CollaboratingPhysicianID() As Nullable(Of Int64)
        Get
            Return _objDoctor.CollaboratingPhysicianID
        End Get
        Set(ByVal Value As Nullable(Of Int64))
            _objDoctor.CollaboratingPhysicianID = Value
            OnPropertyChanged("Doctor")
        End Set
    End Property

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

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

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

    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

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

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

Here is on example of XAML that I could use:

<StackPanel>
        <TextBox Text="{Binding LastName}" />
        <TextBox Text="{Binding Doctor.LastName}" />
    </StackPanel>

I would really prefer to bind to my data as the first textbox is so that I can do validation on changes. (if there is a way to do validation with the second way someone please let me know)

The problem is this:

If I load the doctor in the new constructor of the viewmodel as such:

Public Sub New()
    If IsInDesignMode Then
    Else
        CreateEventSubscriptions()
    End If
    Me.Doctor = DoctorService.GetDoctor(4839)

End Sub

The Databinding works correctly the first time. But if I try to change the associated doctor with an Event, only the doctor.lastname binding works.

    Private Sub onEdit(ByVal d As Doctor)
        Me.Doctor = DoctorService.GetDoctor(d)


    End Sub

I know I dont need to load a doctor from my service because I am actually passing the doctor...I was trying to see if there was something magical about using a service to fill the propery.

I got the code for my viewmodel properties using Karl Shifflet's XAML PowerToys. Knowing that Karl knows what he is doing I am not sure why I cant get this to work....hopefully it is something silly I am missing.

+1  A: 

I believe if you change the doctor during an event, you should also call:

OnPropertyChanged("LastName")

Otherwise I don't think the binding code has any way of knowing the LastName property has been updated.

Phil Sandler
so I need to put that under the doctor property? so each property needs an on propertychanged under doctor? ill try that..thanks
ecathell
That was the magic..thanks...woulda never thought to do that on my own...thanks Phil
ecathell