1

私はwpfプロジェクトで使用したdocumentviewerを使用して、約600ページあるxpsドキュメントレポートを表示しています。これはうまく機能しています。しかし、ユーザーの観点からは、現在のページ番号を表示しているスクロールをドラッグしながら、スクロールビューアーにツールチップとして現在のページ番号を表示するのが好きです。このようなPDFファイルのように-

scrollviewerのツールチップ

私はこれを実装する方法のいくつかのアイデアを探していました。サムネイル画像を表示できない場合は、現在のページ番号だけで十分です。この機能のdocumentviewerに組み込まれたサポートはありますか?

助けてくれてありがとう。

4

1 に答える 1

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でスクロールするのは誰ですか?

于 2011-04-22T22:18:46.963 に答える