The richtext box is of fixed width. And I don't want to show a horizontal scroll. I want to fix the content in the richtextbox with proper wrapping of words.
I have a richtext box with 3 lines. The textwrapping is set to "Wrap" But the text is wrapped like below:
Amazing grace how sweet the sou
nd
That saved a wretch lik
e me
I once was lost but now found
But how I wanted to wrap it is:
Amazing grace how sweet the
sound
That saved a wretch
like me
I once was lost but now found
How do I achieve this? I need it to wrap the text on multiple lines, without trying to prevent words from splitting.
Edited: This is the XAML code:
<RichTextBox FontSize="60" IsReadOnly="True" x:Name="rtbText" BorderThickness="0" Background="Transparent" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,0,0" />
The flowdocument to the richtextbox is assigned during the run time (dynamically)
Adding code and explanation:
There are many richtext boxes in the main window. I save all their flow documents in an array. (main window: array name: fdsongs)
Now in another form, which is shown in Fullscreen, I show one richtext box at a time and assign the flow documents from the array. ( fullscreen: array fdsongs1 is a copy of fdsongs from main window)
Before assigning the flow document in the fullscreen richtext box, I alter the font size and the text alignment of the blocks and then assign the flow document to the richtextbox.
Block[] b1 = fdsongs1[0].Blocks.ToArray();
foreach (Block b in b1)
{
b.TextAlignment = TextAlignment.Center;
b.FontSize = myCalcFontSize;
}
rtbText.Document = fdsongs1[0];
Try this