Search code examples
wpfxamltextbox

XAML - TextBox Linebreak


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" />

Solution

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

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

    Found here