我找不到像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那麼多..會試試這個肯定.. – 2011-04-23 09:11:35
這工作得很好,我有一個查詢,雖然我張貼在這裏 - http://stackoverflow.com/questions/5831514/tooltip-on-scrollviewer-in-documentviewer-in-case-of-deferred-scrolling僅與此相關。你能幫我解決這個問題嗎? – 2011-04-29 17:57:07