title: C#/WPF: Binding to an element outside of the visual/logical tree
body: <p>I'm using the DropDownButton control from the Extended WPF Toolkit. Inside of that, I'm hosting a ListBox which, upon change of selected element, should hide the containing DropDownButton.</p>
  
  <p>My initial approach to do so in conjunction with Microsoft's interactivity framework was:</p>
  
  <pre><code>&lt;xctk:DropDownButton x:Name="WorkspaceSelectorContainer" Content="This is the active workspace"&gt;
                      &lt;xctk:DropDownButton.DropDownContent&gt;
                              &lt;ListBox ItemsSource="{Binding workspaces}"&gt;
                                  &lt;i:Interaction.Triggers&gt;
                                      &lt;i:EventTrigger EventName="SelectionChanged"&gt;
                                          &lt;ie:ChangePropertyAction PropertyName="IsOpen" Value="False" TargetObject="{Binding ElementName=WorkspaceSelectorContainer}"/&gt;
                                      &lt;/i:EventTrigger&gt;
                                  &lt;/i:Interaction.Triggers&gt;
                              &lt;/ListBox&gt;
                          &lt;/StackPanel&gt;
                      &lt;/xctk:DropDownButton.DropDownContent&gt;
                  &lt;/xctk:DropDownButton&gt;
  </code></pre>
  
  <p>But this didn't work as WorkspaceSelectorContainer isn't found. 
  Instead of binding by ElementName, I tried finding the ancestor of type DropDownButton, but this did not work either; tracing the binding showed it only resolved ancestors up to the outer most element of DropDownButton.DropDownContent, but not any further; e.g. the DropDownButton itself wasn't part of the ancestor tree.</p>
  
  <p>Ok, so my next approach was</p>
  
  <pre><code>&lt;ie:ChangePropertyAction PropertyName="IsOpen" Value="False" TargetObject="{Binding Source={x:Reference WorkspaceSelectorContainer}}"/&gt;
  </code></pre>
  
  <p>but that did not work either as it threw an Exception</p>
  
  <pre><code>A first chance exception of type 'System.Xaml.XamlObjectWriterException' occurred in System.Xaml.dll
  
  Additional information: Cannot call MarkupExtension.ProvideValue because of a cyclical dependency. Properties inside a MarkupExtension cannot reference objects that reference the result of the MarkupExtension. 
  </code></pre>
  
  <p>Don't know what else to try anymore. Does anyone have an idea how to solve this?</p>
  
  <p>Would it be possible to somehow reference my root grid that contains everything, and search for the DropDownButton element from there?
  Something like {Binding Source={x:Reference MyRootGrid}, ElementName=WorkspaceSelectorContainer}  (this doesn't work as I can't combine  source and ElementName)</p>
  
  <p>Thanks!</p>