title: Binding is not working for the first time in WPF
body: <p>I have the following code in my sample.</p>
  
  <pre><code> public string MyProperty
   {
       get { return (string)GetValue(MyPropertyProperty); }
       set { SetValue(MyPropertyProperty, value); }
   }
  
   public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.Register("MyProperty", typeof(string), typeof(MainWindow), new PropertyMetadata("Hello"));
  
   private TestClass1 test;
  
   private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
   {
       Binding binding = new Binding
       {
           Path = new PropertyPath("MyProperty"),
           Mode = BindingMode.TwoWay,
           UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
       };
           test.SetValueBinding(binding);
           test.DataContext = this;
           Console.WriteLine(test.Value);
    }
  
    public class TestClass1 : FrameworkElement
    {
        public object Value
        {
            get { return (object)GetValue(ValueProperty); }
            set { SetValue(ValueProperty, value); }
        }
  
        public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(object), typeof(TestClass1), new PropertyMetadata(null));
  
        public void SetValueBinding(Binding binding)
        {
            this.SetBinding(ValueProperty, binding);
        }
     }
  </code></pre>
  
  <p>After binding is set, if  i access test.Value, it returns null for the first time. After that,if i access it (from another method) it returns correct value "Hello".
  But i do not know first time why binding is not working and null value is returned? any suggestion?</p>
  
  <p>Thanks in advance.</p>