title: Sending input from Textbox
body: <p>I have a textbox on my C# WPF project and I want it to send the value inputted into the textbox to a variable into the following function once i press enter. </p>
  
  <p>Does my user input from my textbox have to be in a separate function or can I have it within the same function I want to have the value sent to?</p>
  
  <pre><code>    private void UserInput(object sender, KeyEventArgs e)
      {
          Point p1 = new Point();
          TextBox textBoxX = new TextBox();
          if (e.Key == Key.Enter)
          {
              double inputAsNumberX = 0.0000;
              if (double.TryParse(textBoxX.Text, out inputAsNumberX))
              {
                  p1.X = inputAsNumberX;
              }
              else
              {
                  MessageBox.Show("This is not a number.");
              }
  
          }
          else
          {
          }
  
          double inputAsNumberY = 0;
          TextBox textBoxY = sender as TextBox;
          while (textBoxY.Text == null)
          {
              //textBoxY = sender as TextBox;
          }
          if (double.TryParse(textBoxY.Text, out inputAsNumberY) == true)
          {
              p1.X = inputAsNumberY;
          }
          else
          {
              MessageBox.Show("This is not a number.");
          }
  
  
      } 
  </code></pre>
  
  <p>xaml code</p>
  
  <pre><code>&lt;TextBox Name="TextBoxX" TextWrapping="Wrap" MaxLength="32" KeyDown="UserInput" /&gt;
  </code></pre>
  
  <p>Update:  strange thing i have a question about is that when i try enter anything (while debugging), it stops me from entering anything. after running through the code, and trying to enter again, it allows me to enter one char (like a number) and then stops me from entering more.</p>
  
  <p>it also seems that it only shows the new char typed in the textbox after the code is run.</p>
  
  <p>how can i fix my code to run the way i want, which is to enter a value, press enter, value gets sent to function, which sets it to the double variable: inputAsNumberX???</p>
  
  <p>Update 2:
  I have updated with the code I am using. I am trying to get two inputs so I set up two textboxes. Both should do the same thing as I asked above.</p>