与换行符纲领性文本块入口 [英] programmatic textblock entry with linebreaks
问题描述
如何编程与换行符给TextBlock添加文字
如果我插入的文字是这样的:
helpBlock.Text =下面是一些文字<断行/>此处为<断行/>有的<断行/>更多。
然后换行符得到解释为字符串的一部分。我想这是更喜欢,如果我在XAML中有它,会发生什么
我似乎无法做到这一点的WPF的方式之一:
helpBlock.Inlines.Add(下面是一些内容。);
由于Add()方法,用以接受型内联的对象。
$<$ p:乙
$ b
我不能因为它的保护级别创建一个内联对象,并将它作为参数传递,因为它是无法访问$ p> helpBlock.Inlines.Add(新Windows.UI.Xaml.Documents.Inline(更多文本));
我不明白的方式以编程方式添加运行。
我能找到一吨这样的例子WPF,但没有对WinRT的。
我也翻了很多的XAML的例子,但没有从C#。
您可以只通过在新行 \\\
而不是
<断行/>
helpBlock.Text =这是一些文本。 \\\
下面是一些\\\
更\\\
;
或者在XAML中你会使用新行的六角
值
< TextBlock的文本=这里是一些文本。 &安培;#X0A;下面是与放大器;#X0A;一些和放大器;#X0A;更多/>
这两种结果:
How do I programmatically add text with line breaks to a textblock?
If I insert text like this:
helpBlock.Text = "Here is some text. <LineBreak/> Here is <LineBreak/> some <LineBreak/> more.";
Then the linebreaks get interpreted as part of the string literal. I want it to be more like what would happen if I had it in the XAML.
I can't seem to do it the WPF way either:
helpBlock.Inlines.Add("Here is some content.");
Since the Add() method wants to accept objects of type "inline".
I can't create an Inline object and pass it as a parameter because it is "inaccessible due to its protection level:
helpBlock.Inlines.Add(new Windows.UI.Xaml.Documents.Inline("More text"));
I don't see a way to programmatically add runs.
I can find a ton of WPF examples of this, but nothing for WinRT.
I've also turned up a lot of XAML examples, but nothing from C#.
You could just pass in newline \n
instead of <LineBreak/>
helpBlock.Text = "Here is some text. \n Here is \n some \n more.";
Or in Xaml you would use the Hex
value of newline
<TextBlock Text="Here is some text. 
 Here is 
 some 
 more."/>
Both results:
这篇关于与换行符纲领性文本块入口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!