I have created a RichTextBox with a Fixed Width and Height (Size of A4 Sheet). I would like to scroll the text vertically when the data goes outside the height. I am able to achieve the vertical scroll via mouse wheel by setting the VerticalScrollBarVisibility property to Hidden. Until this everything works fine.
If I change the VerticalScrollBarVisibility property to "Visible", it display the vertical scrollbar attached to the RichTextBox. Since, I am using the fixed width for the RichtextBox, the Scrollbar does not appear at the right side of the window. However, I would like to have a separate Scrollbar to the right of my window (just like every browsers). I have added a separate Vertical Scrollbar to the window. Now the question is, how can I link the Scrollbar event to RichTextBox scrolling?.
<Style x:Key="RichTxtStyle" TargetType="{x:Type RichTextBox}">
<Setter Property="VerticalScrollBarVisibility" Value="Hidden"/>
<Setter Property="HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="AcceptsReturn" Value="True"/>
<Setter Property="Margin" Value="40,0,40,0"/>
<Setter Property="Padding" Value="50,50,50,50"/>
<Setter Property="Width" Value="827"/>
<Setter Property="MinHeight" Value="1169"/>
<Setter Property="BorderThickness" Value="0"/>
</Style>
Here is the Scrollbar object
<ScrollBar x:Name="VerticalScroll" Grid.Row="1" Grid.Column="1" Orientation="Vertical" ValueChanged="VerticalScroll_ValueChanged"/>
Below is the event, I tried. This is where I am totally lost?.
private void VerticalScroll_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
double offset = e.NewValue;
RichTxtBx.ScrollToVerticalOffset(offset);
}