首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FlowDocumentReader滚动到顶部

FlowDocumentReader滚动到顶部
EN

Stack Overflow用户
提问于 2013-08-28 23:04:18
回答 1查看 377关注 0票数 0

如何滚动到FlowDocumentReader的顶部?

通过绑定来设置内容

代码语言:javascript
复制
<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的评论,这将滚动到顶部

代码语言:javascript
复制
FlowDocumentPageViewer1.Document.BringIntoView();

现在我的问题是如何使调用自动化。

我不能把它放在get中,因为我不能把那个命令放在返回之后。

尝试了这两个事件,但未使用绑定更新触发

代码语言:javascript
复制
Loaded="FlowDocumentPageViewer1_loaded"  
SourceUpdated="FlowDocumentPageViewer1_loaded"
EN

回答 1

Stack Overflow用户

发布于 2013-08-29 22:21:51

您可以创建设置原始Document属性并调用BringIntoView()的附加属性

代码语言:javascript
复制
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();
            }
        }
    }
}

现在,您可以像这样绑定此属性:

代码语言:javascript
复制
<FlowDocumentReader ...
    local:FlowDocumentReaderEx.Document="{Binding DocFlow, ElementName=_this}"/>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18491611

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档