如何滚动到FlowDocumentReader的顶部?
通过绑定来设置内容
<FlowDocumentReader Grid.Row="4" Grid.Column="0" Name="FlowDocumentPageViewer1" HorizontalAlignment="Stretch">
<FlowDocumentReader.Document>
<Binding ElementName="_this" Path="DocFlow" IsAsync="False" Mode="OneWay"/>
</FlowDocumentReader.Document>
</FlowDocumentReader>如果我向下滚动,然后绑定新内容,它不会滚动到顶部。
有了新内容,我想滚动到顶部。
根据Clemnes的评论,这将滚动到顶部
FlowDocumentPageViewer1.Document.BringIntoView();现在我的问题是如何使调用自动化。
我不能把它放在get中,因为我不能把那个命令放在返回之后。
尝试了这两个事件,但未使用绑定更新触发
Loaded="FlowDocumentPageViewer1_loaded"
SourceUpdated="FlowDocumentPageViewer1_loaded"发布于 2013-08-29 22:21:51
您可以创建设置原始Document属性并调用BringIntoView()的附加属性
public class FlowDocumentReaderEx
{
public static readonly DependencyProperty DocumentProperty =
DependencyProperty.RegisterAttached(
"Document", typeof(FlowDocument), typeof(FlowDocumentReaderEx),
new FrameworkPropertyMetadata(DocumentPropertyChanged));
public static FlowDocument GetDocument(DependencyObject obj)
{
return (FlowDocument)obj.GetValue(DocumentProperty);
}
public static void SetDocument(DependencyObject obj, FlowDocument value)
{
obj.SetValue(DocumentProperty, value);
}
private static void DocumentPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
var flowDocumentReader = obj as FlowDocumentReader;
if (flowDocumentReader != null)
{
flowDocumentReader.Document = e.NewValue as FlowDocument;
if (flowDocumentReader.Document != null)
{
flowDocumentReader.Document.BringIntoView();
}
}
}
}现在,您可以像这样绑定此属性:
<FlowDocumentReader ...
local:FlowDocumentReaderEx.Document="{Binding DocFlow, ElementName=_this}"/>https://stackoverflow.com/questions/18491611
复制相似问题