【问题标题】:How text from a resource with Environment.NewLine in xaml?如何在 xaml 中使用 Environment.NewLine 来自资源的文本?
【发布时间】:2023-02-22 23:25:02
【问题描述】:

在资源文件 Messages_en.resx 中,我存储了一个文本。
名称:TestView_01
值:您好。这是一个测试。

在 Test.xaml 中,此文本也显示在 TextBlock 中:

<TextBlock x:Name="TextBlockInformation" Text="{x:Static res:Messages_en.TestView_01}" TextWrapping="Wrap" />

这行得通。

现在我想在文本中换行并更改了值(没有 \r\n):
您好。{0}这是一个测试。

在 xaml 中,可以调用命令 Environment.NewLine:
x:静态系统:Environment.NewLine

sys 是 xmlns:sys="clr-namespace:System;assembly=mscorlib"

使用 TextBlock 的 Environment.NewLine 对资源中文本的正确调用是什么?

【问题讨论】:

    标签: wpf xaml


    【解决方案1】:

    而不是 您可以使用特殊字符或数字字符映射。

    https://learn.microsoft.com/en-us/dotnet/desktop/xaml-services/xml-character-entities

     Hello.&#x0a;This is a test.
    

    <Grid>
        <TextBlock Text="Hello.&#x0a;This is a test." TextWrapping="Wrap" />
    </Grid>
    </Window>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多