18

Is there anyway in XAML only to have a linebreak in a TextBox?

I know I can set myTextBox.Text = "something\r\nsomething2" in Code, but I can't do this:

<TextBox x:Name="myTextBox">
    <TextBox.Text>
        Something
        <Linebreak/>
        Something2
    </TextBox.Text>
</TextBox>

or this

<TextBox x:Name="myTextBox" Text="something\r\nsomething2" />
viggity
  • 15,039
  • 7
  • 88
  • 96
  • As per @Dillie-O's reply, this is a duplicate of http://stackoverflow.com/questions/183406/xaml-newline-in-string-attribute – Matt Hamilton Oct 21 '08 at 21:52
  • 4
    Regardless of the OP's intent, this isn't an exact duplicate at all...He's asking about a TextBOX, not a TextBLOCK - which don't function the same when it comes to using . I think this question should be reopened for potential answer/clarification or referred to a question that is actually a duplicate. – Michael Dec 08 '12 at 17:01

1 Answers1

29

Try using &#x0a; to replicate a \r\n like this:

<TextBox x:Name="myTextBox" Text="something&#x0a;something2" />

Found here

rboy
  • 2,018
  • 1
  • 23
  • 35
Dillie-O
  • 29,277
  • 14
  • 101
  • 140