Accepting Input and Assigning Values from a TextBox

What might sound a little confusing for a beginner, is actually very easy: I enter something in my TextBox, and I get a new Value from my Text Block. How do I do that?

What I did was creating a new variable, a string newValue. Then I am setting the new value to the words “you typed: ” plus what I typed in my TextBox and making the new Text inside the TextBlock the new value.

Now this is three lines of code. I’d love if I could get that done in one line. I mean basically I just want some text that I typed in. Let’s see: new value, new text – First I comment out those three lines, and then I am just doing the same thing in one line:

Now, both examples made use of the Click event handler of my button. Meaning I want that code to be executed each time the button is clicked. I could make use of another event, let’s say the Text Changed event.Inside that event handler I just use the same line of code:

What I want to do now is make use of the Loaded event:

I am telling that application to immediately let me type in my TextBox without tapping it first.

I also want to have the possibility to clear both my TextBox and my TextBlock. Since I commented out the code inside my Button click event handler, I can reuse that event. I change the Button content to “Clear” and add two lines of code inside that event handler:

When I run the application now I can indeed clear almost everything. But I also can’t continue typing anything else, without tapping my TextBox again. So apparently my TextBox has lost Focus. Well, by adding that line:

I keep my keyboard visible, and after clearing I can immediately type something new.

 

To be continued…

 

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: