2011-04-22 31 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