Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Line Break or new line in XAML

Tags:

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

like image 482
Rizwan Qureshi Avatar asked Oct 15 '13 16:10

Rizwan Qureshi


People also ask

How do you set a line break?

Press ALT+ENTER to insert the line break.

Is line break same as new line?

Newline (frequently called line ending, end of line (EOL), next line (NEL) or line break) is a control character or sequence of control characters in a character encoding specification (e.g., ASCII, EBCDIC) that is used to signify the end of a line of text and the start of a new one.

What is \n line break?

Adding Newline Characters in a String. Operating systems have special characters denoting the start of a new line. For example, in Linux a new line is denoted by “\n”, also called a Line Feed. In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF.

How do I create a line break in TextBlock WPF?

Adding Line Breaks Sometimes you will want to insert a line break within a TextBlock. You can do this with a LineBreak inline, added as an XAML element within the text. A new line will be started at the position of this element.


2 Answers

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.

like image 173
Chris W. Avatar answered Oct 02 '22 19:10

Chris W.


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> 
like image 32
nmclean Avatar answered Oct 02 '22 19:10

nmclean