Result of Silverlight WCF Service on UI

Topics: Prism v4 - WPF 4
Jul 21, 2011 at 1:24 PM

Hi all!

In my project I've created a component (Silverlight WCF component) that connects to a database, gets data from there and shows the data in a listbox. It works async and responds to the INotifyPropertyChanged event in order to show the data. The component displays itself in a region on the UI.

In another project, intended to handle all the UI, I have a Shell with some regions. The ViewModel is responsible for instatiating the component like so:


Dim MyComponent As New SLComponent.Component1

MyComponent.Initialize '//This is where the component does it's own work



It works async and responds allright. I know that, because in Fiddler, I see the XML data filled with the desired information. But the component and the empty listbox show up in the intended Region, yet the listpart of the listbox remains empty. I have set the DisplayMemberPath to one of the properties of the object that is shown.

Does anyone have any suggestions on how to get the UI responding to the async update of the component?


Jul 21, 2011 at 1:28 PM

Hi Peter,

You should make sure that you've set your binding correctly, and that your ViewModel implements INotifyPropertyChanged (by manually implementing it, or making your ViewModel inherit from NotificationObject). Also, you should make sure you're raising the PropertyChanged event each time your information is obtained from the server.

I hope you find this helpful.

Guido Leandro Maliandi

Jul 21, 2011 at 2:58 PM

Hi Guido, thanks for getting back to me so fast. I really appreciate that.

As far as I can see I have the NotifyPropertyChanged events on places where they should be. This is the code for the component:

Imports System.Collections.ObjectModel
Imports SLComponent.PersoonProxy

Public Class Component1ViewModel
    Inherits ViewModelBase

    Private ReadOnly MijnProxy As New MensenServiceClient

    Public Property Personen As New ObservableCollection(Of Persoon)

    Public Sub New()
        If Not IsDesignTime Then
        End If
    End Sub

    Private Sub OphalenPersonen()
        LeesPersonen(Sub(s, e) Personen = e.result)

    End Sub

    Private Sub LeesPersonen(ByVal callback As EventHandler(Of LeesAllePersonenCompletedEventArgs))

        AddHandler MijnProxy.LeesAllePersonenCompleted, callback
    End Sub

End Class

The listbox that is on the visible part of the component is bound to this ViewModel as shown below:

        <ViewModel:Component1ViewModel x:Key="MijnViewModel"/>
    <Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource MijnViewModel}}">
        <ListBox Name="ListBox1" ItemsSource="{Binding Path=Personen}" DisplayMemberPath="BSN" />

IMHO on every async update of the Observablecollection(of Personen), this listbox will show the newly fetched data, right?

Then eventually in the UI project, the component assembly is referenced to from that UI project and it is instantiated with the call I gave in my first post. Somewhere along the road something gets lost...

Any suggestions? Do you need more codesnippets? All help is welcome!



Jul 21, 2011 at 5:37 PM

FOUND the solution!

The OnPropertyChanged should not be set inside of the async call, where it gets updated allright. Instead, it has to be set inside the Property Setter.. SO in the above code, the automated property will have to be changed into a property with backing store. And inside of the Setter, the OnPropertyChanged. Like so:

    Private _personen As ObservableCollection(Of Persoon) = New ObservableCollection(Of Persoon)()
    Public Property Personen() As ObservableCollection(Of Persoon)
            Return _personen
        End Get
        Set(ByVal value As ObservableCollection(Of Persoon))
            _personen = value
        End Set
    End Property


Thanks for your attention!


Jul 21, 2011 at 5:58 PM

Hi Peter,

Thank you for sharing your insight with the rest of the community, as it might benefit other users facing similar problems.


Guido Leandro Maliandi