title: Binding programmatically doesn't work when I add the controls in run-time
body: <p>I have two TextBoxes and I want to bind between their Visibility property in run time,</p>
  
  <p>The binding works when I add the TextBoxes by Xaml but doesn't work when I add them programmatically,</p>
  
  <p>Any help !!</p>
  
  <pre><code>    public partial class Window1 : Window
      {
          TextBox txt1 = new TextBox();
          TextBox txt2 = new TextBox();
          public Window1()
          {
              InitializeComponent();
  
              txt1.Name = "txt1";
              txt1.Margin= new Thickness(30,0,128,0);
              txt1.VerticalAlignment = VerticalAlignment.Top;
  
              txt2.Name = "txt2";
              txt2.Margin = new Thickness(30, 32, 128, 0);
              txt2.VerticalAlignment = VerticalAlignment.Top;
  
              Binding binding = new Binding();
              binding.ElementName = "txt1";
              binding.Path = new PropertyPath(TextBox.VisibilityProperty);
              BindingOperations.SetBinding(txt2, TextBox.VisibilityProperty, binding);
  
  
              grid.Children.Add(txt1);
              grid.Children.Add(txt2);
          }
      }
  </code></pre>
  
  <p>Thanks in advance</p>