zoukankan      html  css  js  c++  java
  • 2018-11-17-win10-uwp-在-xaml-让-TextBlock-换行

    title author date CreateTime categories
    win10 uwp 在 xaml 让 TextBlock 换行
    lindexi
    2018-11-17 16:2:29 +0800
    2018-11-17 15:35:37 +0800
    Win10 UWP

    本文告诉大家几个方法在 xaml 的 TextBlock 的 Text 换行

    在 xaml 可以使用 
 表示换行,所以最简单的方法是在 Text 里面输入 
 换行

    如显示下面的图片,可以使用下面代码

            <TextBlock Text="换行的最简单方法&#x0a;欢迎访问我博客 lindexi.gitee.io 里面有大量 UWP WPF 博客
    " 
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center" />

    如果换行需要使用 可以在 xaml 使用 &#x0d;&#x0a; 替换

    如果是在 WPF 可以通过 LineBreak 的方法换行

            <TextBlock HorizontalAlignment="Center"
                       VerticalAlignment="Center">
                <TextBlock.Text>
                    换行的最简单方法
                    <LineBreak/>
                    欢迎访问我博客 lindexi.gitee.io 里面有大量 UWP WPF 博客
                </TextBlock.Text>
            </TextBlock>

    但是上面的方法无法在 UWP 使用

    好在可以使用xml:space="preserve"直接输入换行

            <TextBlock xml:space="preserve">
                <TextBlock.Text>
                    换行的最简单方法
                    欢迎访问我博客 lindexi.gitee.io 里面有大量 UWP WPF 博客
                </TextBlock.Text>
            </TextBlock>

    添加了 space 就可以在换行的时候自动换行

    如果担心在 元素 上添加 xml:space="preserve" 会让其他的功能不好用,可以使用资源的方法,请看代码

            <Grid.Resources>
                <x:String x:Key="str" xml:space="preserve">
                    换行的最简单方法
                    欢迎访问我博客 lindexi.gitee.io 里面有大量 UWP WPF 博客
                </x:String>
            </Grid.Resources>
            <TextBlock HorizontalAlignment="Center" 
                       VerticalAlignment="Center" Text="{StaticResource str}">
             
            </TextBlock>

    使用了 xml:space="preserve" 会将行前的空格也加上

  • 相关阅读:
    Vim Reference
    Java 8 Consumer、Supplier、Predicate、Function
    Java 8 Stream 用法
    Java 基础 Builder模式
    Spring/Spring-Boot 学习 使用自定义的ArgumentResolver
    架构之分布式图片存储系统架构
    微服务和SOA服务
    Centos 上 Tengine安装
    .NET平台上插拔姿势的AOP
    P1424 刷题记录
  • 原文地址:https://www.cnblogs.com/lindexi/p/12086513.html
Copyright © 2011-2022 走看看