【发布时间】:2016-09-22 23:06:17
【问题描述】:
我有一个与 flowDocument 关联的 wpf 富文本框。 假设从 1..60 开始对流文档中的行进行编号 富文本框不够高,无法显示所有数字。
但这很好,因为我可以滚动鼠标滚轮。 问题是这个过程滚动不够,如下图所示:
您可能会看到,这里它只是到达第 50 行而不是第 60 行。 这不是与其他元素重叠的问题。
提前感谢您的帮助。 帕特里克
---添加--- 这是xml
<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>
与
<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>
--添加2---
我用
填充流文档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)));
}
}
和那个
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;
}
--加3-- 解决方案的更多线索: 如果读取的文件包含数字 1..60,通过向下滚动到最大值,效果是:
[![enter code here][3]][3]
如果我通过向下滚动到最大添加更多带有字母 a...z 的行,效果是:
远远超过 60 岁!!!!但不是z
【问题讨论】:
-
你能分享 XAML 吗?
-
当然!请看我的补充。谢谢
-
它滚动对我来说很好。
-
向上滚动到第 60 行??
-
等一下,我刚刚意识到我忘记了 FlowDocument 部分。你是如何填充文本的?
标签: c# wpf richtextbox flowdocument