Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you want to child objects to see as if they are part of a their parent directly you need to do the bubbling yourself.</p> <p>For your example, you would be binding to 'Address.Street' in your view, so you need to bubble a notifypropertychanged containing that string.</p> <p>I wrote an easy helper to do this. You just call BubblePropertyChanged(x => x.BestFriend) in your parent view model constructor. n.b. there is an assumption you have a method called NotifyPropertyChanged in your parent, but you can adapt that to suit.</p> <pre><code> /// &lt;summary&gt; /// Bubbles up property changed events from a child viewmodel that implements {INotifyPropertyChanged} to the parent keeping /// the naming hierarchy in place. /// This is useful for nested view models. /// &lt;/summary&gt; /// &lt;param name="property"&gt;Child property that is a viewmodel implementing INotifyPropertyChanged.&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; public IDisposable BubblePropertyChanged(Expression&lt;Func&lt;INotifyPropertyChanged&gt;&gt; property) { // This step is relatively expensive but only called once during setup. MemberExpression body = (MemberExpression)property.Body; var prefix = body.Member.Name + "."; INotifyPropertyChanged child = property.Compile().Invoke(); PropertyChangedEventHandler handler = (sender, e) =&gt; { this.NotifyPropertyChanged(prefix + e.PropertyName); }; child.PropertyChanged += handler; return Disposable.Create(() =&gt; { child.PropertyChanged -= handler; }); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload