title: How to programmatically add WPF binding between DependencyProperty objects on 2 separate windows
body: <p>The problem I am having is probably very simple to solve, yet it seems tricky from beginner's perspective.</p>
  
  <p>I created 2 windows visible simultaneously, one with ListBox on it, another with TextBox. I would like to bind window1.ListBox.SelectedValue to window2.TextBox.Text property programmatically. I am not using value converters.</p>
  
  <p>The code is straightforward:</p>
  
  <pre><code>      var binding = new Binding("SelectedValue");
        binding.Source = window1.ListBox;
  //      binding.Path = new PropertyPath(ListBox.SelectedValueProperty);
        var bound = window2.TextBox.SetBinding(TextBlock.TextProperty, binding);
  </code></pre>
  
  <p>I would like to bind using DependencyProperty instance instead of property name for performance reasons, but I also tried binding by name. Binding just does not work.</p>
  
  <p>You can download dummy VS2010 project <a href="https://turecki.net/download/so/dummy.7z" rel="nofollow">here</a>.</p>
  
  <p>This leads to another question - how to debug binding, which event (if any) to subscribe to detect Binding changes ?</p>