title: WPF Adorner Visibility Data Binding programmatically
body: <p>I'm creating a Loading Adorner that has a swirling icon over it. I tried binding the visibility property directly in the XAML but that actually hides everything inside its hierarchy.</p>
  
  <p>I have this in my XAML:</p>
  
  <pre><code>&lt;AdornerDecorator Visibility="{Binding Path=RootGroup.Loading, Converter={StaticResource VisibilityConverter}}"&gt;
      &lt;TreeView x:Name="groupTreeView" /&gt;
  &lt;/AdornerDecorator&gt;
  </code></pre>
  
  <p>and this in my constructor</p>
  
  <pre><code>LoadingAdorner adorner = new LoadingAdorner(groupTreeView);
  AdornerLayer.GetAdornerLayer(groupTreeView).Add(adorner);
  </code></pre>
  
  <p>This isn't want I wanted so I tried binding it in the code instead:</p>
  
  <pre><code>LoadingAdorner adorner = new LoadingAdorner(groupTreeView);
  Binding bind = new Binding("RootGroup.Loading");
  bind.Source = this.DataContext;
  bind.Converter = new VisibilityConverter();
  adorner.SetBinding(LoadingAdorner.VisibilityProperty, bind);
  AdornerLayer.GetAdornerLayer(groupTreeView).Add(adorner);
  </code></pre>
  
  <p>This will work if the DataContext is not null because it can actually find RootGroup.Loading. But if it is null then the binding has no source to look at.</p>
  
  <p>So I was wondering what does the XAML databinding use as its .Source ? Binding directly in the XAML binds to the correct property, but it doesn't achieve the same result. So I'm just wondering what I should be setting my .Source to So i can bind to RootGroup.Loading ?</p>
  
  <p>Thanks,
  Raul</p>