title: TextBox in UserControl, can't edit Text dependency property from code behind
body: <p>My UserControl contains a TextBox and a Button. The TextBox's Text is correctly populated by a dependency property called X.</p>
  
  <p><strong>My Goal:</strong>
  Change the value of X (e.g. Text of the TextBox) when I press the Button.</p>
  
  <p>I have defined the UserControl as follows:</p>
  
  <pre><code>&lt;StackPanel Orientation="Horizontal" &gt;
      &lt;TextBox Name="Xbox" Text="{Binding Path=X}" Width="50"/&gt;
      &lt;Button Content="Current" Click="InsertCurrentBtnClick" /&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>With codebehind:</p>
  
  <pre><code>    public double X
      {
          get { return (double)GetValue(XProperty); }
          set { SetValue(XProperty, value); }
      }
  
      public static readonly DependencyProperty XProperty =
          DependencyProperty.Register("X", typeof(double), typeof(MyUserControl), new PropertyMetadata(0.0));
  
  
      private void InsertCurrentBtnClick(object sender, RoutedEventArgs e)
      {
          X = 0.7;
  
          //BindingOperations.GetBindingExpression(this, XProperty).UpdateTarget();
          //BindingOperations.GetBindingExpression(Xbox, TextBox.TextProperty).UpdateTarget();
          //BindingOperations.GetBindingExpression(Xbox, XProperty).UpdateTarget();
          //Xbox.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
          //GetBindingExpression(XProperty).UpdateTarget();
      }
  </code></pre>
  
  <p>I have tried several things - one at a time - (see below <code>X=0.7;</code>) to force the update to the TextBox Text but nothing has helped so far.</p>
  
  <p>Thanks in advance.</p>