Why is the View allways one step behind after a property-update in the ViewModel?

Aug 31, 2014 at 8:09 AM
Edited Aug 31, 2014 at 9:18 PM
In Prism , MVVM, Windows 8.1 StoreApp I want the ViewModel to capture the SelectItem of a ListView. The ListView contains an ObservableCollection of Person-objects. The ViewModel needs to lookup more details of the selected Person and notify the View. The View in turn should show the details of the Person.

I have implemented this, but the View allways shows the former object (after selecting a new one)

Of course what I'm looking for is an immediate and correct reaction in the View on selecting an object. Here are my codesnippets, all in VB code.

The objects come from the ViewModel as:
Public Property Persons As New ObservableCollection(Of Person)
They are bound to a usercontrol:
<Grid>
    <ListView 
                ItemsSource="{Binding Persons}" 
                ItemTemplate="{StaticResource BusinessCard}">
        <Interactivity:Interaction.Behaviors>
            <Core:EventTriggerBehavior EventName="SelectionChanged">
                <Behaviors:ListViewSelectionChangedAction/>
            </Core:EventTriggerBehavior>
        </Interactivity:Interaction.Behaviors>
    </ListView>
</Grid>
Via the Behavior eventually this ends up in the ViewModel through this code:
Sub New(InjectedEventAggregator As IEventAggregator)
        LocalEventAggregator = InjectedEventAggregator
        LocalEventAggregator.GetEvent(Of PersonIsSelectedEvent)().Subscribe(AddressOf HandlePersonIsSelected, True)
End Sub
This event is handled by this routine
    Public Sub HandlePersonIsSelected(ByVal SelectedPerson As Person)
        ActualPerson = SelectedPerson
    End Sub
The last part of all this is the property that contains the ActualPerson like so:
    Private Property _ActualPerson As Person
    Public Property ActualPerson As Person
        Get
            Return _ActualPerson
        End Get
        Set(value As Person)
            SetProperty(_ActualPerson, value)
        End Set
    End Property
And finally, there is a StackPanel on the View, that is bound to the (newly selected??) Person through this bit of XAML:
<StackPanel DataContext="{Binding ActualPerson}">
    <Image Source="{Binding Afbeelding}" />
    <StackPanel>
        <TextBlock Text="{Binding FirstName}" />
        <TextBlock Text="{Binding FamilyName}" />
        <TextBlock Text="{Binding Gender}" />
    </StackPanel>
</StackPanel>
The ListView where the selection is done and the StackPanel where the Person would have to be shown, are on the same View, and so they are AutoWired to the same ViewModel.

When I step through the code, I can see that the SelectedItem event is caught in the ViewModel, the handler for the selected person is called, and the property ActualPerson is updated. Using Prism, because the viewmodel derived from ViewModel, this would also mean, that the NotifyPropertyChanged event is fired. It DOES GET FIRED indeed, otherwise the former object would not show either I presume??

But why is the View not updated immediatelty with the right (Person) object?

If you have a clue.... be my honored guest!

Regards