How to Line Break or new line in XAML

2020-02-24 13:17发布

问题:

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

回答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.



回答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>