title: Having trouble binding the Visibility of a ContentPresenter in WPF
body: <p>I have the following XAML:</p>
  
  <pre><code>&lt;UserControl.Resources&gt;
  
  &lt;DataTemplate x:Key="ExpanderTemplate"&gt;
      &lt;Grid&gt;
          &lt;Rectangle Stroke="Black" StrokeThickness="1" Width="10" Height="10" Fill="White" /&gt;
          &lt;Rectangle Stroke="Black" StrokeThickness="1" Width="6" Height="1" Fill="Black" /&gt;
          &lt;Rectangle Stroke="Black" StrokeThickness="3" Width="2" Height="6" Fill="Black" /&gt;
      &lt;/Grid&gt;
  &lt;/DataTemplate&gt;
  
  &lt;DataTemplate x:Key="CollapserTemplate"&gt;
      &lt;Grid&gt;
          &lt;Rectangle Stroke="Black" StrokeThickness="1" Width="10" Height="10" Fill="White" /&gt;
          &lt;Rectangle Stroke="Black" StrokeThickness="1" Width="6" Height="1" Fill="Black" /&gt;
      &lt;/Grid&gt;
  &lt;/DataTemplate&gt;
  
  &lt;/UserControl.Resources&gt;
  
  &lt;Grid&gt;
  &lt;StackPanel Orientation="Horizontal"&gt;
      &lt;TextBlock Text="{Binding Path=Name}" /&gt;
      &lt;Grid&gt;
          &lt;ContentPresenter x:Name="ExpanderPresenter" ContentTemplate="{StaticResource ExpanderTemplate}" Visibility="{Binding ExpanderVisibility}" /&gt;
          &lt;ContentPresenter x:Name="CollapserPresenter" ContentTemplate="{StaticResource CollapserTemplate}" Visibility="{Binding CollapserVisibility}" /&gt;
      &lt;/Grid&gt;
  &lt;/StackPanel&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>As you can see, it's essentially a textblock with its contents bound to a name, and two contentpresenters which have their visibility bound to a couple of Visibility objects on the source class.  The source class looks like this:</p>
  
  <pre><code>public class MyViewModel
  {
  public string Name { get; set; }
  
  public Visibility CollapserVisibility
  {
      get
      {
          if (IsExpandable &amp;&amp; IsExpanded)
          {
              return Visibility.Visible;
          }
          else
          {
              return Visibility.Collapsed;
          }
      }
  }
  
  public Visibility ExpanderVisibility
  {
      get
      {
          if (IsExpandable &amp;&amp; !IsExpanded)
          {
              return Visibility.Visible;
          }
          else
          {
              return Visibility.Collapsed;
          }
      }
  }
  
  public bool IsExpanded { get; set; }
  public bool IsExpandable { get; set; }
  }
  </code></pre>
  
  <p>The problem I am experiencing is that the bindings with the Visibility objects never even happen.  The binding with the Name string <em>does</em> happen, and I have verified that (both visually and by expanding out and putting a breakpoint in the getter), but when I put breakpoints in the getters of the CollapserVisibility and ExpanderVisibility objects, those breakpoints never even get hit.  Why is this?  I'm also not getting any binding errors in the output window of Visual Studio, which further confuses me, so it acts as if the binding was set up correctly.</p>
  
  <p>Am I not allowed to bind the Visibility property of a ContentPresenter?  I also tried moving the Visibility bindings to be on the "Grid" objects in the data templates (in the XAML), but to no avail...it didn't work.  </p>
  
  <p>What's wrong with my binding?  Thanks for any help.</p>