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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7835260/
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-09-08 23:08:56  来源:igfitidea点击:

using tab and carriage return character in a WPF resource dictionary

wpfxamlresourcedictionary

提问by AliRezza

How can I use tab and carriage return characters in a WPF XAML resource dictionary?

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

This doesn't work for me:

这对我不起作用:

<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>

when I retrieve this via FindResource("test_key"), both the tab and carriage return characters are removed.

当我通过 FindResource("test_key") 检索它时,制表符和回车符都被删除。

回答by Johannes Kommer

The XAML parser uses whitespace normalisation (as per MSDN) if you want to avoid this add xml:space="preserve"to your XML as such:

XAML 解析器使用空白规范化(根据MSDN),如果您想避免将这种添加xml:space="preserve"到您的 XML 中:

<system:String x:Key="test_Key" xml:space="preserve">Tab doesnt work&#x09;Test&#x0d;Test</system:String>

回答by Muhammad Hasan Khan

Add newline like so &#x0d;&#x0a;and tab with &#x09;

像这样添加换行符&#x0d;&#x0a;并使用制表符&#x09;

However this won't work unless you've turned off white-space normalization as J.Kommer suggests

但是,除非您按照 J.Kommer 的建议关闭了空白规范化,否则这将不起作用