Refreshing A Wpf Databinding After Object Has Been Updated

- 1 answer

I have a object in a presenter connected to a view. Inside my XAMTL I have the following:

<Label Content="{Binding ElementName=PSV, Path=Presenter.Portfolio.Name}"/>

Now when the control is created, Portfolio is null, then i run another method which sets Portfolio. I've implemented INotifyPropertyChanged but so far, I've not been able to trigger to hookup to the binding.

Can someone give me tips? Can I bind to a property of a property ?



Binding always works with the DataContext you would need to set your Presenter into the local DataContext. For example you could do this in the constructor of your Window or UserControl:

this.DataContext = new Presenter();

Your binding would then change to:

<Label Content="{Binding ElementName=PSV, Path=Portfolio.Name}"/>

The Presenter part of your former path is implicit in the DataContext.

This way the DataContext is watching for the NotifyChanged events and will update the view properly when Portfolio changes from null to having a value.

In answer to the final part of your question, binding to a property of a property does work.