0
votes

I am trying to load a Rich Text Format (RTF) file into a WPF RichTextBox. When I perform the load, it appears as though the file is getting loaded into the RichTextBox but the scroll bar is displayed without a visible slider box to scroll download. The scrollbar does not show the bottom arrow so it appears the bottom of the scrollbar is below the display area for the RichTextBox. This prevents a user from being able to scroll downward. I believe I am either missing a XAML property for the RichTextBox or something is not right with the way I am loading the RTF file. Please help. Thanks in advance.

   <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
         </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
         </Grid.RowDefinitions>

        <StackPanel Grid.Row="0" Grid.RowSpan="5" 
                    Grid.Column="0" Grid.ColumnSpan="3" 
                    VerticalAlignment="Stretch" HorizontalAlignment="Stretch">

            <RichTextBox x:Name="LicenseRichTextBox" Margin="10"
                    VerticalAlignment="Stretch" HorizontalAlignment="Stretch"                 

                  IsReadOnly="True"  VerticalScrollBarVisibility="Visible">
            </RichTextBox>
        </StackPanel>
             <StackPanel Grid.Row="6"  Grid.Column="1" Grid.ColumnSpan="3" Margin="65,20,0,0" >
                <Button  x:Name="CloseButton" HorizontalAlignment="Left"
                      Width="90" Margin="-10,0,0,0"
                     Click="CloseButton_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="{StaticResource CloseButtonImageKey}" 
                           Margin="5,0,0,0" Height="20" Width="20" />
                        <TextBlock Padding="5,0,0,0" VerticalAlignment="Center"><Run Text="Close"/></TextBlock>
                    </StackPanel>
                </Button>
            </StackPanel>    
    </Grid>



   public  void LoadRTF()
    {
      const string EULA_Dir = @"Resources\EULA\EUlA.RTF";
      string currentDir = AppDomain.CurrentDomain.BaseDirectory;
      string PathToEULA = currentDir + EULA_Dir;

      if (File.Exists(PathToEULA))
      {
         LicenseRichTextBox.Selection.Load(new FileStream(PathToEULA, FileMode.Open), DataFormats.Rtf);
      }
      else
      {
        MessageBox.Show("Unable to locate the following file " + PathToEULA);
      }
    }
1
Can you show a screenshot? Also, click in the Rich Text Area and Scroll via Direction Keys or Mouse scroll - Does that work??Prateek Shrivastava

1 Answers

1
votes

Wild guess - your RichTextBox is inside a StackPanel. Stack panels do not constrain their children, instead they have infinite internal space and grow according to their child content. So your text box isn't being constrained, so it doesn't think it needs to show a scrollbar.

Not in front of a dev environment at the moment so I can't confirm this but try taking it out of the StackPanel and see what that does.