Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RichTextBox showing texts vertically

Tags:

c#

wpf

Following XAML code:

<ScrollViewer HorizontalScrollBarVisibility="Auto"
              VerticalScrollBarVisibility="Auto">

    <DockPanel LastChildFill="True">
        <TextBox Name="textBox1" DockPanel.Dock="Top" />

        <GroupBox Header="All Events" DockPanel.Dock="Top">
            <RichTextBox Margin="5" Name="richTextBoxEvents"
                         HorizontalScrollBarVisibility="Auto"
                         VerticalScrollBarVisibility="Auto" />
        </GroupBox>
    </DockPanel>
</ScrollViewer>

causes everything displayed in the RichTextBox vertically!

Vertical text in RichTextBox

I want the text to appear horizontally. Why is this appearing vertically and how can I fix that?

I'm using C#, WPF and .NET 4.

EDIT

If the ScrollViewer is taken away, then the text appear horizontally. But I need the scroll viewer. What's the solution then?

like image 351
Donotalo Avatar asked Sep 19 '13 04:09

Donotalo


2 Answers

A similar scenario can be found here.

Your problem can be solved by setting the width of the RichTextBox.

  1. By setting some arbitrary width.

    <RichTextBox Margin="5" Name="richTextBoxEvents"
                     HorizontalScrollBarVisibility="Auto"
                     VerticalScrollBarVisibility="Auto"
                     Width="100" />
    
  2. Or you can assign the width of the Parent.

    <RichTextBox Margin="5" Name="richTextBoxEvents"
                     HorizontalScrollBarVisibility="Auto"
                     VerticalScrollBarVisibility="Auto"
                     Width="{Binding RelativeSource={RelativeSource FindAncestor, 
                     AncestorType=Window, AncestorLevel=3}, Path=ActualWidth}" />
    

Here you can change the ancestor level depending on your needs,I bind the RichTextBox width to the Window's width and AncestorLevel is 3.

like image 68
Naren Avatar answered Oct 07 '22 23:10

Naren


RichTextBox will always word wrap, so I'm assuming that the ScrollViewer is forcing it to start word wrapping.

If you remove the auto visibility, then it works as expected and you'll still get your scrollbars:

<ScrollViewer>
        <DockPanel LastChildFill="True">
            <TextBox Name="textBox1" DockPanel.Dock="Top" />
            <GroupBox Header="All Events" DockPanel.Dock="Top">
                <RichTextBox Margin="5" Name="richTextBoxEvents" />
            </GroupBox>
        </DockPanel>
    </ScrollViewer>
like image 35
Nathan Dace Avatar answered Oct 08 '22 00:10

Nathan Dace