Search code examples
c#silverlightwindows-phone-7textboxline-breaks

Linebreak in TextBox


How can I get a linebreak in TextBox in WP7? I'm developing social-based app(like facebook) and if I set AcceptReturn=true, it gives me a visual(ui) linebreak, but when I send this text to the server I can see that there is no linebreak. Please help me with this problem. I've tried

void whatsend_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) {
      if (e.Key == Key.Enter) {
        whatsend.Text +="\r";//or /n,
      }
    }

but with no success.


Solution

  • Windows uses \r\n for line breaks, not \r, but that's irrelevant; use Environment.NewLine instead.

    Also, per the docs:

    true if the ENTER key creates a new line of text in a multiline version of the control; false if the ENTER key activates the default button for the form. The default is false.

    Did you set MultiLine to true?

    EDIT: Ahhh, WP7... here is an article I found which attempts to create a multi-line textbox in WP7.