如何在Windows Phone 8.1应用程序中打印新行TextBlock

时间:2015-07-17 07:35:18

标签: c# xaml windows-phone-8 windows-phone-8.1

我是XAML的新手,似乎无法理解如何为Textblock编写代码,我可以在其余的代码运行时继续添加新的文本行。我基本上想要做的是为Windows手机编写一个简单的应用程序,它执行一项简单的任务,每次遇到响应或错误时,都会在UI中打印到此Textblock,而不是像日志或Debug.WriteLine或Console.WriteLine。有人可以帮助我,或者至少告诉我在哪里可以学习如何自己做?我可以看到徒劳无功的搜索。

我已经尝试过Textblock.text + = string,但它似乎根本没有更新。

2 个答案:

答案 0 :(得分:2)

使用取消代码

        <TextBlock Text="Newline1 &#x0a; Newline2 &#x0a; Newline3"></TextBlock>

使用LineBreak

        <TextBlock Margin="0,20,0,0">Line1<LineBreak></LineBreak>Line2<LineBreak></LineBreak>Line3</TextBlock>

使用TextWrap属性 Link

 <TextBlock Margin="0,20,0,0" TextWrapping="Wrap" >
        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </TextBlock>

最终的xaml代码

  <StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <!--Using Uncode &#x0a; -->
    <TextBlock Text="Newline1 &#x0a; Newline2 &#x0a; Newline3"></TextBlock>

    <!--Using LineBreak Tag -->
    <TextBlock Margin="0,20,0,0">Line1<LineBreak></LineBreak>Line2<LineBreak></LineBreak>Line3</TextBlock>

   <!--Using TextWrap property  -->

    <TextBlock Margin="0,20,0,0" TextWrapping="Wrap" >
        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </TextBlock>
</StackPanel>

<强>输出

enter image description here

使用c#

In C#, what's the difference between \n and \r\n?

答案 1 :(得分:1)

在c#中为textblock添加新行可以这样做:

tb.Text += "Hello" + Environment.NewLine + "Dude";

使用“+ =”只需附加字符串。 使用“Environment.NewLine”为您提供换行符。