title: Setting template binding in code behind
body: <p>The output 'm expecting is something like this,</p>
  
  <pre><code>&lt;Canvas Width="800" Height="600"&gt;
     &lt;Ellipse Stroke="#FF000000" StrokeThickness="2" Width="284" Height="288" 
              ToolTip="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Min}" 
              Canvas.Left="312" Canvas.Top="122" /&gt;
  &lt;/Canvas&gt;
  </code></pre>
  
  <p>With this code,</p>
  
  <pre><code>//This will ultimately hold object of type UIElement, which is Ellipse in this case.
  private DependencyObject selectedObject; 
  
  public void AddBinding(DependencyProperty dependencyProperty, DependencyProperty ipartProperty)
  {
      Binding binding = new Binding(ipartProperty.Name); //Here Name is Min, an attached property
      binding.RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent);
      BindingOperations.SetBinding(selectedObject, dependencyProperty, binding);
  }
  </code></pre>
  
  <p>But actual output is</p>
  
  <pre><code>&lt;Canvas Width="800" Height="600"&gt;
     &lt;Ellipse Stroke="#FF000000" StrokeThickness="2" Width="284" Height="288" 
              ToolTip="{x:Null}" Canvas.Left="312" Canvas.Top="122"/&gt;
  &lt;/Canvas&gt;
  </code></pre>
  
  <p>I don't know whats wrong, can someone please help</p>