Documentviewer中滚动查看器的工具提示 [英] Tooltip on scrollviewer in documentviewer

查看:145
本文介绍了Documentviewer中滚动查看器的工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 -

我一直在寻找一些实现此想法的想法.如果不能显示缩略图,仅显示当前页码对我来说就足够了. 在documentviewer中是否对此功能有任何内置支持?

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??

感谢您的帮助.

推荐答案

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

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

该事件还会在通过鼠标滚轮等完成的滚动上触发.您可以将处理程序中的所有内容包装在if (Mouse.LeftButton == MouseButtonState.Pressed)中,但并非100%准确,但是谁可以在不使用鼠标滚轮的情况下将鼠标滚动点击?

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?

这篇关于Documentviewer中滚动查看器的工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆