WPF标签中的换行符? [英] Newline in a WPF-label?
问题描述
如何在WPF中的标签文本中添加换行符,如下所示?
How can I add a newline in the text of a label in WPF such as the following?
<Label>Lorem
ipsum</Label>
推荐答案
<Label><TextBlock>Lorem<LineBreak/>ipsum</TextBlock></Label>
您需要使用TextBlock,因为TextBlock接受Inline对象的集合作为子代.因此,您为TextBlock元素提供了三个内联项:Run Text ="Lorem",LineBreak和Run Text ="ipsum".
You need to use TextBlock because TextBlock accepts as children a collection of Inline objects. So you are giving the TextBlock element three Inline items: Run Text="Lorem", LineBreak, and Run Text="ipsum".
您不能执行以下操作:
<Label>Lorem<LineBreak/>ipsum</Label>`
因为标签接受一个内容子元素.
because a label accepts one content child element.
此外,不确定确切的用例是什么,但是请注意,我在您的Label元素内放置了一个TextBlock.它是重复的吗?并非完全如此,取决于您的需要.这是一篇很好的文章,介绍了这两个元素之间的区别: Label和TextBlock之间的区别
Also, not sure exactly what your use case is but notice I placed a TextBlock inside your Label element. Is it repetitive? Not really, depending on your need. Here's a good article on the differences between the two elements: Difference between Label and TextBlock
这篇关于WPF标签中的换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!