2011-04-22 64 views
1

我有一个文档查看器,我在我的wpf项目中使用,以显示大约600页的xps文档报告,这些报告运行良好。但是,从用户的角度来看,我喜欢在当前页面编号显示为我的滚动查看器上的工具提示,同时拖动显示当前页码的滚动条。有点像这样的PDF文件 -在文档查看器中滚动查看器的工具提示

Tooltip on scrollviewer

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

感谢您的帮助..

回答

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而左键单击?

+0

这对我来说是新鲜事物,从来没有玩过PopUp那么多..会试试这个肯定.. – 2011-04-23 09:11:35

+0

这工作得很好,我有一个查询,虽然我张贴在这里 - http://stackoverflow.com/questions/5831514/tooltip-on-scrollviewer-in-documentviewer-in-case-of-deferred-scrolling仅与此相关。你能帮我解决这个问题吗? – 2011-04-29 17:57:07