title: WPF UserControl Context Menu Visibility Binding
body: <p>My user control context menu visibility can't bind a dependency property. Any idea?</p>
  
  <p>Here is my WPF code </p>
  
  <pre><code>&lt;UserControl.ContextMenu&gt;
      &lt;ContextMenu Visibility="{Binding ElementName=wellControl, Path=IsInCompactMode, Converter={StaticResource BooleanToVisibilityConverter}}"&gt;
      &lt;MenuItem Command="local:GCommands.Edit" /&gt;
      &lt;MenuItem Command="local:GCommands.Delete" /&gt;
      &lt;MenuItem Command="local:GCommands.ExportFcsFiles" /&gt;
      &lt;MenuItem Command="local:GCommands.BatchExportStatistics" /&gt;
      &lt;Separator/&gt;
      &lt;MenuItem Command="local:GCommands.SaveAs" Header="Save As..." /&gt;
      &lt;/ContextMenu&gt;
  &lt;/UserControl.ContextMenu&gt;
  </code></pre>
  
  <p>If I set Visibility="Hidden" it will work for me.
  like this:</p>
  
  <pre><code>&lt;ContextMenu Visibility="Hidden"/&gt;
  </code></pre>
  
  <p>If use this it won't work</p>
  
  <pre><code>&lt;ContextMenu Visibility="{Binding ElementName=wellControl, Path=IsInCompactMode, Converter={StaticResource BooleanToVisibilityConverter}}"&gt;
  </code></pre>
  
  <p>I'm pretty sure Visibility="{Binding ElementName=wellControl, Path=IsInCompactMode, Converter={StaticResource BooleanToVisibilityConverter}}" has not problem, cuz it works for others.</p>
  
  <p>here is my dependency property</p>
  
  <pre><code>public bool IsInCompactMode
          {
              get {return (bool)GetValue(IsInCompactModeProperty); }
              set {SetValue(IsInCompactModeProperty, value); }
          }
          public static readonly DependencyProperty IsInCompactModeProperty =
              DependencyProperty.Register("IsInCompactMode", typeof(bool), typeof(WellControl), new PropertyMetadata(false));
  </code></pre>
  
  <p>I tried this way, it seems it still doesn't work, this is really weird!!!</p>
  
  <pre><code>&lt;ContextMenu x:Name="menu" IsOpen="{Binding ElementName=wellControl, Path=IsInCompactMode}"&gt; 
  </code></pre>
  
  <p>I'm really confuse about it, what's wrong? "Binding ElementName=wellControl, Path=IsInCompactMode" works for other part of the user control, just doesn't work for the weird context menu? it doesn't make sence</p>