How to Line Break or new line in XAML

35,740

Solution 1

You've got options. For example;

<HyperlinkButton Content="Line One&#10;Line Two"/>

or

<HyperlinkButton>
  <HyperlinkButton.Content>
    <TextBlock>
      <Run Text="Line 1"/><LineBreak/><Run Text="Line 2"/>
    </TextBlock>
  </HyperlinkButton.Content>
</HyperlinkButton>

Hope this helps.

Addendum: You can do this stuff in basically anything. WPF, Silverlight, UWP, whatever. It's not WP specific.

Solution 2

You can use preserve. It includes all whitespace, so inputting the exact string you want would involve messing up your indentation, but this will work:

        <HyperlinkButton xml:space="preserve">This is line one.
This is line two.</HyperlinkButton>
Share:
35,740

Related videos on Youtube

Rizwan Qureshi
Author by

Rizwan Qureshi

I am a student of Master in Computer Science &amp; trying to become a good programmer. Desktop, Mobile and Web developer are the main focus of my field using Microsoft's .Net technologies.

Updated on December 22, 2020

Comments

  • Rizwan Qureshi
    Rizwan Qureshi over 3 years

    I am having hard time to match Special characters set in XAML. I only on the following:

    To represent a LineBreak in XAML hyperlink button:

    use : > lineBreak <

    But What do I use to represent a New Line or LineBreak In XAML hyperlink button??

    Example : I want this one line mag : This is line one. This is line two

    into this :

    This is line one. This is line two.

    it seems this \r\n is not working. This is line one \r\n

  • Arsal
    Arsal almost 9 years
    'Unexpected 'ATTRIBUTE' in parse rule 'NonemptyPropertyElement ::= . PROPERTYELEMENT Content? ENDTAG.'.' Line number '14' and line position '33'. I Got above error with xml:space="preserve". how this can be resolved.?
  • rfreytag
    rfreytag almost 9 years
    You sir, are a ninja. Minimal input with maximum result.
  • Unoembre
    Unoembre over 6 years
    This is very useful as it can also be used on other display elements such as TEXTBLOCK
  • Robert Gowland
    Robert Gowland about 4 years
    +1 for <LineBreak/>. Expecting our translators to know what to do with &#10 will result in nothing but heartache.
  • Erisvaldo Junior
    Erisvaldo Junior almost 3 years
    This worked well for me, if you have to extract text later is very useful.