Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

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

Download

Right click “Save as…”

This video shows the Silverlight control properties and how those properties can be used to set and retrieve attributes of the object (such as the Text attribute) or, rather, the control. Beyond the use of the TextBox control, understanding how properties can be set and retrieved on objects is an important building block as we begin to learn more about classes and objects.

Download the source code in c#

Download the source code in VB.Net

Follow the Discussion

  • Carsten HansenCarsten 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.

  • Clint RutkasClint I'm a "developer"

    @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.

  • edrandomedrandom

    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. :)

  • great

  • why9why9

    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.

  • ALFALF

    @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.

  • 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.

  • AbhinavAbhinav

    @sokhaty.....good explanation :)

  • 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?

  • YosamiteYosamite

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

  • Great! Thaks a lot

  • rubyruby

    hi,
    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.

  • @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.

  • RickyRicky

    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?

  • RyanRyan

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

  • JoshJosh

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

  • anthonyanthony

    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;

    not

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

  • Yengi LadoYengi 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.

Remove this comment

Remove this thread

close

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.