多行WPF文本块:不同的对齐线 [英] Multiline WPF textblock: different alignment for lines

查看:1325
本文介绍了多行WPF文本块:不同的对齐线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是可以设置不同的水平对齐方式为不同的线路多行文本块的?

Is that possible to set different horizontal alignment for different lines of multiline textblock?

例如,我要居中我的文字的标题,但正文我想通过左边对齐。我不想用一些的TextBlocks此问题。

For example, I want to center header of my text, but main text I want to align by left side. I'd not want to use several textblocks for this issue.

感谢。

推荐答案

我不认为你可以得到你所期待的使用TextBlock控件,这是因为内联元素,你可以添加你的TextBlock不允许来控制水平取向(逐行)。

I do not think you can get what you are looking for using the TextBlock control, this because the Inline elements that you can add in your TextBlock does not allow you to control the horizontal alignment (line by line).

无论如何,我不认为这是最好的方法,其实,指定由MSDN:

Anyway I do not think that this is the best approach, in fact, as specified by MSDN:

TextBlock的是不适用于需要比内容的几行,以显示更多的方案优化;对于这样的情况,再加上适当的观看控制的FlowDocument是一个更好的选择,而不是TextBlock的,在性能方面。的TextBlock后,FlowDocumentScrollViewer是下最轻量控制用于显示流内容,并简单地提供具有最小的UI滚动内容区域。 FlowDocumentPageViewer的优化也是围绕页面时,一时间观看模式为流量的内容。最后,FlowDocumentReader支持观看流内容最丰富的功能,但也相应加重重量。

TextBlock is not optimized for scenarios that need to display more than a few lines of content; for such scenarios, a FlowDocument coupled with an appropriate viewing control is a better choice than TextBlock, in terms of performance. After TextBlock, FlowDocumentScrollViewer is the next lightest-weight control for displaying flow content, and simply provides a scrolling content area with minimal UI. FlowDocumentPageViewer is optimized around "page-at-a-time" viewing mode for flow content. Finally, FlowDocumentReader supports the richest set functionality for viewing flow content, but is correspondingly heavier-weight.

所以,如果你想拥有更灵活的控制,同时也更好地在性能方面为你问它做什么,你应该使用的的FlowDocument

So if you want to have more flexible control, and also better in terms of performance for what you ask it to do, you should use the FlowDocument.

我想补充最后一句话。如果你正在寻找性能的显着改善,而你认为​​一个单一的TextBlock是正确的解决方案,我建议使用的视觉元素和相对的 DrawText的的方法来代替。但是,如果你正在寻找一个易于控制,未来的选择的FlowDocument维护,前面已经说了。

I want to add a final remark. If you're looking for a dramatic improvement in performance, and you think that a single TextBlock is the right solution, I suggest to use Visual elements and the relative DrawText method instead. But if you're looking for an easy control to maintain in the future the choice is FlowDocument, as already said.

这篇关于多行WPF文本块:不同的对齐线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆