问题
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