在WPF文本块中获取段落的最佳方法是什么? (换行符?) [英] What the best way to get paragraphs in a WPF textblock? (newline chars?)
本文介绍了在WPF文本块中获取段落的最佳方法是什么? (换行符?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些带有"\ r \ n"换行符的文本.我想在WPF文本块中使用换行符.我尝试将"\ r \ n"替换为 " (不带空格),该功能在我在XAML中设置Text属性时有效,但在从C#代码后面进行设置时似乎不起作用.
I have some text which has "\r\n" newline markers. I would like to have the newlines in a WPF textblock. I've tried replacing "\r\n" with "& # 13;" (without the spaces), which worked when I set the Text property in XAML, but doesn't seem to work when setting from the C# code-behind.
那么...在WPF文本块中将"\ r \ n"转换为换行符的标准方法是什么?
So...what's the standard way to convert "\r\n" to newlines in a WPF textblock?
推荐答案
尝试这些以获取更多以WPF为中心的解决方案.
Try these for a more WPF centric solution.
TextBlock.Inlines.Add(new Run("First"));
TextBlock.Inlines.Add(new LineBreak());
TextBlock.Inlines.Add(new Run("Second"));
另请参见:基于XAML的答案
这篇关于在WPF文本块中获取段落的最佳方法是什么? (换行符?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文