C# 如何在 XAML 中换行或换行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19386577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 14:52:08  来源:igfitidea点击:

How to Line Break or new line in XAML

c#.netsilverlightxamlwindows-phone-7

提问by Rizwan Qureshi

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

我很难匹配 XAML 中设置的特殊字符。我只谈以下几点:

To represent a LineBreak in XAML hyperlink button:

要在 XAML 超链接按钮中表示 LineBreak:

use : > lineBreak <

使用:> lineBreak <

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

但是我用什么来表示 XAML 超链接按钮中的新行或换行符?

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

示例:我想要这一行 mag:这是第一行。这是第二行

into this :

进入这个:

This is line one. This is line two.

这是第一行。这是第二行。

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

看来这\r\n 不起作用。这是第一行\r\n

采纳答案by Chris W.

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.

附录:你基本上可以在任何事情上做这些事情。WPF、Silverlight、UWP 等等。这不是特定于 WP 的。

回答by nmclean

You can use preserve. It includes allwhitespace, 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>