views:

120

answers:

1

Hi.

I am binding WPF with Entity-Framework.

The Window.DataContext property is set to a Quote. This Quote has a property Job, that I have to trigger Quote.JobReference.Load it should load from the server.

<ContentControl Content="{Binding Job}" 
    ContentTemplate="{StaticResource JobTemplateSummary}"/>

As you can see above, I am trying to bind a ContentControl to the Window's DataContext which is a StaticResource Quote class.

I am calling the Load in the Window.Load even handler. Should I've called somewhere else?

A: 

The problem was that Navigation Properties don't call ProertyChanged event by default so when the window is bound (which is before Page_Load handler) the JobReference was still not Loaded, we have to call Quote.OnPropertyChanged("Job") explicitly when the job property changes, so the WPF UI knows to refersh the control binding.

I added the following to the Quote class, and this solved the problem:

    Public Sub New()
        AddHandler JobReference.AssociationChanged, _
            AddressOf Job_AssociationChanged
    End Sub

    Sub Job_AssociationChanged(sender As Object, e As CollectionChangeEventArgs)
        OnPropertyChanged("Job")
    End Sub
Shimmy