views:

164

answers:

1

Hi,

I'm trying to change the content of a ContentPresenter to one of my View Model class. I manage to have it shown properly, once I change this content (property) from my model, it doesn't update the ui.

The following lines link my view model classes to their respective ui (setting their data context automatically) :

<DataTemplate DataType="{x:Type vm:WelcomePageViewModel}">
            <vw:WelcomePage></vw:WelcomePage>
 </DataTemplate>

 <DataTemplate DataType="{x:Type vm:UnitPageViewModel}">
            <vw:UnitPage></vw:UnitPage>
 </DataTemplate>

I want to show the ui using binding:

<ContentPresenter Content="{Binding CurrentChildViewModel}" />

So in my ViewModel class, I have a CurrentChildViewModel property, which is an Instance of a closableViewModel. I first assign it in the constructor.

But now when I change the value of my CurrentChildViewModel, it won't update the ui, even if the property is changed in the viewmodel, the first element assigned will stay.

I don't see what I'm doing wrong here. Maybe I'm not using the right architecture (method) to change the content of an element.

Your help would be much appreciated. Thanks in advance,

Boris

+2  A: 

Make sure to implement INotifyPropertyChanged. The data binding framework doesn't constantly "poll" for changes to the bindings, but relies on the property change framework to fire off the updates for bindings.

Jeff Wilcox
Thanks, actually my "base" abstract class implements the INotifyPropertyChanged but I didn't call the OnPropertyChange function.
Boris Gougeon