文档查看器中滚动查看器上的工具提示

发布于 2024-11-02 22:18:24 字数 293 浏览 0 评论 0原文

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

Scrollviewer 上的工具提示

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

感谢您的帮助..

I have a documentviewer which i used in my wpf project to show xps document reports of having around 600 pages which is working great. But from user point of view i like to show the current page number as a tooltip on my scrollviewer while dragging the scroll stating the current page number in view. Somewhat like in a PDF file like this -

Tooltip on scrollviewer

I was looking out for some ideas how to implement this. Just a current page number if not possible to show a thumbnail image would be good enough for me.
Is there any in-built support in documentviewer for this functionality??

Thanks for any help..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

东北女汉子 2024-11-09 22:18:24

我找不到像 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 滚动?

I cannot find anything like IsScrolling so i would approach it like this:

<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"/>

The popup should be displayed when the document is scrolled, then it should fade out after some time. This is done in the handler:

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;
}

Edit: The event fires also on scrolls done via mouse-wheel etc. you could wrap everything in the handler in if (Mouse.LeftButton == MouseButtonState.Pressed), not 100% accurate but who scrolls with the MouseWheel while left-clicking?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文