在WPF资源字典中使用制表符和回车符

Ali*_*zza 20 wpf xaml resourcedictionary

如何在WPF XAML资源字典中使用制表符和回车符?

这对我不起作用:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:system="clr-namespace:System;assembly=mscorlib"
                >

<system:String x:Key="test_Key">Tab doesnt work\tTest\rTest</system:String>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

当我通过FindResource("test_key")检索它时,tab和回车字符都被删除.

Joh*_*mer 23

如果要避免这样添加到XML,XAML解析器使用空格规范化(根据MSDN)xml:space="preserve":

<system:String x:Key="test_Key" xml:space="preserve">Tab doesnt work&#x09;Test&#x0d;Test</system:String>
Run Code Online (Sandbox Code Playgroud)


Muh*_*han 20

像这样添加换行符&#x0d;&#x0a;和tab&#x09;

然而,除非你像J.Kommer所暗示的那样关闭了白空间规范化,否则这将无效