2

私は WPF DocumentViewer コントロールを使用して、次のように XPS ドキュメントを表示しました。

viewer.Document = xpsDocument.GetFixedDocumentSequence();

ドキュメント ビューア内の印刷ボタンをクリックすると、すべて正常に印刷されますが、印刷ジョブの名前は System.Windows.Documents.FixedDocumentSequence であり、理想的とは言えません。

印刷ジョブの名前を設定するにはどうすればよいですか?

PrintDialog.PrintDocument() を使用すると名前を設定できることはわかっていますが、DocumentViewer コントロールを使用してそれを行う方法がわかりません。

4

2 に答える 2

4

解決策を見つけました。

これを XAML に追加します。

<Window.CommandBindings>
    <CommandBinding Command="ApplicationCommands.Print" PreviewExecuted="CommandBinding_PreviewExecuted" Executed="CommandBinding_Executed" />
</Window.CommandBindings>

そして、これはコードビハインドに

private void CommandBinding_PreviewExecuted(object sender, ExecutedRoutedEventArgs e)
{
    PrintDialog dialog = new PrintDialog();
    if (dialog.ShowDialog() == true)
    {
        dialog.PrintDocument(Document.DocumentPaginator, "Print Job Title");
    }
}

private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
    //needed so that preview executed works
}

注意すべきことがいくつかあります。Exectued イベントがバインドされていない場合、PreviewExecuted メソッドは実行されません。理由がわからない。

于 2009-02-26T01:43:31.490 に答える
3

私は同じ問題を抱えていましたが、印刷コマンドをオーバーライドしても私の状況では機能しないため、同じように機能する別の回避策を見つけました

internal class MyDocumentViewer : DocumentViewer
{
    public string JobTitle { get; set; }

    protected override void OnPrintCommand()
    {
        PrintDialog dialog = new PrintDialog();
        if (dialog.ShowDialog() == true)
            dialog.PrintDocument(Document.DocumentPaginator, JobTitle);
    }
}
于 2012-07-15T16:48:46.360 に答える