C# WPF RichTextEdit shows 1 character per line

Wayne Hamberg 0 Reputation points
2025-04-21T16:15:24.0933333+00:00

I have in a C# WPF application a RichTextEdit that is defined as

        <RichTextBox Grid.Row="1" x:Name="txtHebrew" FlowDirection="RightToLeft"

                                                     HorizontalAlignment="Stretch"

                                                     VerticalAlignment="Stretch"

                                                     FontSize="20"

                                                     FontFamily="David"

                                                     IsReadOnly="True"

                                                     VerticalScrollBarVisibility="Auto"

                                                     Margin="5" IsDocumentEnabled="True"/>

I am populating that control in the code behind with this code.

            control.txtHebrew.Document.Blocks.Clear();

            string hebrewtext = verse.HebrewText;

            FlowDocument document = new FlowDocument()

            {

                FlowDirection = FlowDirection.RightToLeft,

                TextAlignment = TextAlignment.Right,

                PageWidth = control.Width,

                FontSize = 20,

                FontFamily = new FontFamily("David"),

                ColumnWidth = double.PositiveInfinity

            };

            control.txtHebrew.Document = document;

            Paragraph paragraph = new(new Run(hebrewtext))

            {

                FlowDirection = FlowDirection.RightToLeft,

                TextAlignment = TextAlignment.Right,

                Margin = new Thickness(0),

                Padding = new Thickness(0)

            };

            document.Blocks.Clear();

            document.Blocks.Add(paragraph);

I get 1 character per line and I have done everything to get this to change and even changed the text to English with the same problem. I have searched online and even tried ChatGPT to no avail. Nothing works.

User's image

I have to be not including something that isn't mentioned in the documentation. What am I not doing?

Developer technologies | XAML
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 60,326 Reputation points
    2025-04-21T16:29:13.54+00:00

    Dropping your code into a blank WPF app and setting hebrewtext to a static string value properly renders the text on a single line. Honestly your code seems a little convoluted if all you're doing is setting a RichTextbox to some text. A simple binding seems easier and likely might solve your issue.

    It is also unclear where your actual code is executing. It seems like it is in an event handler but I'm not sure. I have no idea what control actually is. Can you please provide us a minimal repro block of code including any method(s) you're implementing that are related to this block of code? Also, use a simple static string value for your variable to confirm it works for that. If it does then it is likely verse.hebrewtext variable that is messing things up.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.