Wpf RichTextBox wrapping problems

一笑奈何 提交于 2019-12-24 05:00:13

问题


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 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)).

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>

回答1:


You have to place the RichTextBox in a ScrollViewer.

<ScrollViewer>
   <RichTextBox>
        ...
   </RichTextBox>
</ScrollViewer>


来源:https://stackoverflow.com/questions/14797814/wpf-richtextbox-wrapping-problems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!