title: MVVM - binding to aggregated property
body: <p>I have following viewmodels:</p>
  
  <pre><code>public class ViewModel: INotifyPropertyChanged
  {
      public ObservableCollection&lt;Item&gt; Items { get; set; }
      ...
  }
  public class Item: INotifyPropertyChanged
  {
      public SubItem A { get; set; }
      public SubItem B { get; set; }
      ...
  }
  public class SubItem: INotifyPropertyChanged
  {
      public bool Valid { get; set; }
      ...
  }
  </code></pre>
  
  <p>xaml:</p>
  
  <pre><code>&lt;ListBox ItemsSource="{Binding Items}" ..&gt;
  </code></pre>
  
  <p>If I want to display text <code>"Valid item"</code> if both <code>A.Valid</code> and <code>B.Valid</code> are <code>true</code>, then:</p>
  
  <ol>
  <li><p>I can do this by having logic in the view (item data template), e.g using visibility and extra container:</p>
  
  <pre><code>&lt;Grid Visibility="{Binding A.Valid}" Converter=...&gt;
      &lt;TextBlock Text="Valid item" Visibility="{Binding B.Valid}" Converter=... \&gt;
  &lt;/Grid&gt;
  </code></pre></li>
  <li><p>Or I can add a new property to item viewmodel:</p>
  
  <pre><code>public class Item: INotifyPropertyChanged
  {
      public bool Valid =&gt; A.Valid &amp;&amp; B.Valid; // bind to this
      ...
  }
  </code></pre>
  
  <p>The problem is that notifications of either of <code>SubItem</code> will not update the view.</p></li>
  </ol>
  
  <p>In case of (1) the binding will subscribe to both <code>PropertyChanged</code> events: <code>Item</code> and corresponding <code>SubItem</code>. In case of (2) the binding only knows about <code>Item.Valid</code> property, so I have to do something like:</p>
  
  <pre><code>public class Item: INotifyPropertyChanged
  {
      SubItem _a;
      public SubItem A
      {
          get { return _a; }
          set
          {
              _a.PropertyChanged -= bla;
              _a = value;
              _a.PropertyChanged += bla;
              OnPropertyChanged(nameof(A));
              OnPropertyChanged(nameof(Valid));
          }
      }
      void bla(object sender, PropertyChangedEventArgs e) =&gt;
          OnPropertyChanged(nameof(Valid));
      ...
  }
  </code></pre>
  
  <p>Which is awful. So I prefer (1) (using data triggers sometimes, but it's irrelevant).</p>
  
  <p>Are there other options to actually have viewmodel property (2) but without the hassle?</p>