【问题标题】:Tooltip on scrollviewer in documentviewer文档查看器中滚动查看器的工具提示
【发布时间】:2011-04-22 19:10:48
【问题描述】:

我有一个文档查看器,我在我的 wpf 项目中使用它来显示大约 600 页的 xps 文档报告,效果很好。但是从用户的角度来看,我喜欢在滚动查看器上将当前页码显示为工具提示,同时拖动滚动条,说明当前视图中的页码。有点像这样的 PDF 文件 -

我一直在寻找一些想法来实现这一点。如果无法显示缩略图,只需一个当前页码对我来说就足够了。 文档查看器中是否对此功能有任何内置支持??

感谢您的帮助..

【问题讨论】:

    标签: wpf wpf-controls scrollviewer documentviewer xpsdocument


    【解决方案1】:

    我找不到像 IsScrolling 这样的东西,所以我会这样处理它:

    <Popup Name="docPopup" AllowsTransparency="True" PlacementTarget="{x:Reference docViewer}" Placement="Center">
        <Border Background="Black" CornerRadius="5" Padding="10" BorderBrush="White" BorderThickness="1">
            <TextBlock Foreground="White">
                        <Run Text="{Binding ElementName=docViewer, Path=MasterPageNumber, Mode=OneWay}"/>
                        <Run Text=" / "/>
                        <Run Text="{Binding ElementName=docViewer, Path=PageCount, Mode=OneWay}"/>
            </TextBlock>
        </Border>
    </Popup>
    <DocumentViewer Name="docViewer" ScrollViewer.ScrollChanged="docViewer_ScrollChanged"/>
    

    当文档滚动时应该显示弹出窗口,然后它应该在一段时间后淡出。这是在处理程序中完成的:

    DoubleAnimationUsingKeyFrames anim;
    private void docViewer_ScrollChanged(object sender, ScrollChangedEventArgs e)
    {
        if (anim == null)
        {
            anim = new DoubleAnimationUsingKeyFrames();
            anim.Duration = (Duration)TimeSpan.FromSeconds(1);
            anim.KeyFrames.Add(new DiscreteDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0))));
            anim.KeyFrames.Add(new DiscreteDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5))));
            anim.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1))));
        }
    
        anim.Completed -= anim_Completed;
        docPopup.Child.BeginAnimation(UIElement.OpacityProperty, null);
        docPopup.Child.Opacity = 1;
    
        docPopup.IsOpen = true;
    
        anim.Completed += anim_Completed;
        docPopup.Child.BeginAnimation(UIElement.OpacityProperty, anim);
    }
    
    void anim_Completed(object sender, EventArgs e)
    {
        docPopup.IsOpen = false;
    }
    

    编辑:该事件也会在通过鼠标滚轮等完成的滚动时触发。您可以将处理程序中的所有内容包装在 if (Mouse.LeftButton == MouseButtonState.Pressed) 中,不是 100% 准确,而是在左侧使用 MouseWheel 滚动 -点击?

    【讨论】:

    • 这对我来说是新事物,从来没有玩过 PopUp 这么多.. 肯定会尝试这个..
    • 这工作得很好,我有一个查询,不过我在这里发布了一个查询-stackoverflow.com/questions/5831514/… 仅与此相关。你能帮我解决这个问题吗???
    猜你喜欢
    • 1970-01-01
    • 2019-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多