Wpf RichTextBox 包装问题 [英] Wpf RichTextBox wrapping problems
本文介绍了Wpf RichTextBox 包装问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 WPF
的 RichTextBox
中遇到文本换行问题,当我得到如下文本时:
I am having a problems with text wrapping in WPF
's RichTextBox
, when I get the text like:
TextRange tr = new TextRange(rtb.Document.ContentStart,
rtb.Document.ContentEnd);
tr.Text
没有任何\r\n",但在视觉控制中它看起来应该是(当输入到达 RichTextBox
边界时它会换行(插入行尾)).
tr.Text
doesnt have any "\r\n", but in visual control it looks like it should be (it wraps when input reaches RichTextBox
border (inserts end of the line)).
我像这样创建 RichTextBox:
I create RichTextBox like this:
<RichTextBox Name="Rtb" AcceptsReturn="True" AcceptsTab="True" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Height="100" Margin="15,125,5,45" Width="272">
<FlowDocument LineHeight="1" IsColumnWidthFlexible="true" >
<Paragraph LineStackingStrategy="MaxHeight">
<Run Text="RichTextBox"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
推荐答案
您必须将 RichTextBox 放置在 ScrollViewer 中.
You have to place the RichTextBox in a ScrollViewer.
<ScrollViewer>
<RichTextBox>
...
</RichTextBox>
</ScrollViewer>
这篇关于Wpf RichTextBox 包装问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文