Accepting Input and Assigning Values from a TextBox - Day 1 - Part 10

Play Accepting Input and Assigning Values from a TextBox - Day 1 - Part 10

The Discussion

  • User profile image
    Carsten Hansen

    When hitting the Clear button you clear the Text property of myTextBlock in the Event Handler. But in the emulator it appears as "You typed:". Maybe you should explain why that happens.

  • User profile image

    @Carsten Hansen: that is because the "TextChanged" event fired when the Click event for the clear button set the text box's text to an empty string.

  • User profile image

    Amazing you need no do whiles aso! Finally I got the clue, the objects are vm self supporting, "event driven" makes sense to me now. But... still feeling like waking up in a huge building with corridors and a lot of doors with just some obscure code written where to go. No windows, just Bob. I uncovered my blindfold, switch the light on now Bob, exiting here! I trust you, don't lose me now. :)

  • User profile image


  • User profile image

    In the clear button you don't need to set myTextBlock=""; When you clear the the myTextBox it will automatically update the the myTextBlock. Other than that great video.

  • User profile image

    @Clint: That's right, but the TextBlock is cleard after the TextBox, so the TextBlock should be empty aswell. This is what happens if click the Button twice.
    I don't understand that.

  • User profile image

    It looks like mystery about lost update to myTextBlock.Text revolves around implementation specifics of event processing in Silverlight on WP7 (or may be Silverlight in general?).
    Apparently, when assignment myTextBox.Text = ""; happens, "on text change event" is being added to the end of the queue of events waiting to be processed. So, queued event will be picked up for porcessing only after myButtonClick event handler completes. And when that happens, all your changes to the myTexBlock.Text will be effectively undone, lost or what have you. This is quite esy to validate by clicking "Clear" button without entering any text immediately after application loads, or clicking it twice in a row after some text was entered. In this case "on text change" event won't be fired (presumably changing text form "" to "" doesn't constitute a change). You'll note that text block won't display any text.

    I guess a real take away from this episode is how easy it is to mess thing up big, whithout understanding what events are and how they are being processed at run time.

  • User profile image

    @sokhaty.....good explanation :)

  • User profile image

    How can you remedy the situation when you want to display say like a paragraph? The text block only accomodates one line of words and the rest are cut off?

  • User profile image

    I assume the settings for text flow etc are in the textblock properties

  • User profile image

    Great! Thaks a lot

  • User profile image

    this is really helpful to me but can u tell me how can if i want to use my own build up keypad for entering the text in textbox but  i don't want the default keypad to pop up.
    Or i say how can i stop poping of default keypad.

  • User profile image

    @ruby: I hope I answer your question. Once the emulator pops up and you see the keypad, hit the Page Up button on your keyboard and you should be able to use your keyboard.

  • User profile image

    i've an error on the line i typed out " newValue = " You typed:" = myTextBox.Text;" and it says Error The left-hand side of an assignment must be a variable, property or indexer. Was there a mistake tht i typed out to get this error?

  • User profile image

    I had the same problem as Ricky above me, any help?

  • User profile image

    Me too... same as Ricky and Ryan. I copied what Bob typed but there is that error.

  • User profile image

    You need to declare the variable newValue before initializing. You need to first type
    string newValue;

    Also it is supposed to be

    newValue = "You typed:" + myTextBox.Text;


    newValue = "You typed:" = myTextBox.Text;

  • User profile image
    Yengi Lado

    Too bad I can't listen to dubstep and do this
    at the same time :(. Great videos btw but in the beginning when you put newValue = MyTextBlock.Text it wasn't workin out for me. It gave me an error saying MyTextBlock can't except strings. I just skipped it and it turns out I didn't need that line to get the program to work but I was wondering why it didn't work.

Add Your 2 Cents