I have a wpf richtextbox associated with a flowDocument.
Supposing to number lines in the flowdocument from 1..60
The richtextbox is not tall enough to show all numbers.
But that's fine since I can scroll through the mouse wheel. The problem is that this procedure doesn't scroll enough as you can see in the following picture:
You may see that here it merely gets to line 50 instead than to line 60. It's not a problem of overlapping with other elements.
Thank you in advance for any help. Patrick
---ADD--- Here's the xaml
<Grid Name="grdReport_RTF" Visibility="Hidden">
<RichTextBox x:Name="rtbReport_RTF" Margin="10" BorderBrush="Gray" Background="White" Foreground="Black" IsEnabled="True" Padding="10" Style="{DynamicResource rtbStyleDocLocal}" />
</Grid>
with
<Style x:Key="rtbStyleDocLocal" TargetType="{x:Type RichTextBox}">
<Style.Resources>
<Style x:Key="{x:Type FlowDocument}" TargetType="{x:Type FlowDocument}">
<Setter Property="OverridesDefaultStyle" Value="true"/>
</Style>
<Style x:Key="{x:Type Hyperlink}" BasedOn="{StaticResource {x:Type Hyperlink}}" TargetType="{x:Type Hyperlink}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Foreground" Value="Blue"/>
</Trigger>
<Trigger Property="IsEnabled" Value="true">
<Setter Property="Foreground" Value="Black"/>
</Trigger>
</Style.Triggers>
</Style>
</Style.Resources>
<Setter Property="MinWidth" Value="10"/>
<Style.BasedOn>
<StaticResource ResourceKey="{x:Type TextBoxBase}"/>
</Style.BasedOn>
</Style>
--ADD2---
I populate the flowdoc with
Application.Current.Dispatcher.Invoke(new Action(() => fdocRTB.Blocks.Clear()));
if (File.Exists(strCompleteFilename))
{
using (var sr = new StreamReader(strCompleteFilename))
{
String line = sr.ReadToEnd();
Application.Current.Dispatcher.Invoke((Action)(() => fdocRTB = AddLineToRtb(fdocRTB_Beretta, line, false, RTB_LINEHEIGHT, RTB_FONTSIZE)));
}
}
and with that
private FlowDocument AddLineToRtb(FlowDocument fdoc, string str, bool IsTitle, double lineHeight, double fontSize)
{
Paragraph par;
var run = new Run(str);
run.Foreground = Brushes.Black;
if (!IsTitle)
run.FontWeight = FontWeights.Normal;
else
run.FontWeight = FontWeights.Black;
run.FontSize = fontSize;
run.FontFamily = ffRtb;
par = new Paragraph() { LineHeight = lineHeight, FontSize = fontSize };
par.Inlines.Add(run);
Application.Current.Dispatcher.Invoke((Action)(() => fdoc.Blocks.Add(par)));
return fdoc;
}
--Add 3-- Some more clues to the solution: if the read file contains numbers 1..60 by scrolling down to the max the effect is:
[![enter code here][3]][3]
instead if I add some more lines with letter a...z by scrolling down to the max the effect is:
so well beyond 60!!!! But not to z