title: Binding to a sibling's child element
body: <p>I'm working on a UserControl (named DiagramControl) and have a problem. The UserControl's code is as follows:</p>
  
  <pre><code>&lt;UserControl&gt;
     &lt;Border&gt;
        &lt;Grid&gt;
           &lt;ScrollViewer x:Name="DesignerScrollViewer" ... /&gt;               
           ...
           &lt;s:ZoomBox x:Name="zoomBox"
                     ScrollViewer="{Binding ElementName=DesignerScrollViewer}"/&gt;
        &lt;/Grid&gt;
     &lt;/Border&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>I am binding the ZoomBox (which has a scrollviewer DP) to DesignerScrollViewer. The method I use now works fine since the ZoomBox and DesignerScrollViewer are in the same XAML file.</p>
  
  <p>What I would like to do however is to remove the ZoomBox from the control and define it in the window that uses the control. so for example something like:</p>
  
  <pre><code>&lt;Grid&gt;
     &lt;s:DiagramControl x:Name="DC" ... /&gt;
     ...
     &lt;s:ZoomBox ScrollViewer={Binding ElementName=DC,Path=DesignerScrollViewer}/&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>I tried this but it doesn't work. How can I perform the binding that I need?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I figured out what I needed to do. I added a ScrollViewer DP to DiagramControl and had it update when the DesignerScrollViewer's Layout was updated. so the following went into my DiagramControl code behind:</p>
  
  <pre><code>        public static readonly DependencyProperty ScrollViewerProperty =
              DependencyProperty.Register("ScrollViewer", typeof(ScrollViewer), typeof(DiagramControl), new UIPropertyMetadata(null, ScrollViewer_PropertyChanged));
  
          public ScrollViewer ScrollViewer
          {
              get { return (ScrollViewer)GetValue(ScrollViewerProperty); }
              set { SetValue(ScrollViewerProperty, value); }
          }
  
          private static void ScrollViewer_PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
          {                
          }
  
          private void DesignerScrollViewer_LayoutUpdated(object sender, EventArgs e)
      {
          ScrollViewer = DesignerScrollViewer;
      }
  </code></pre>
  
  <p>Now that the ScrollViewer DP had an update source i was able to bind to it from the window using the DiagramControl. Hope this helps someone in future.</p>