DocumentViewerのコントロールを使用するときにどのように私は、印刷ジョブの名前を設定するのですか?

StackOverflow https://stackoverflow.com/questions/588662

  •  09-09-2019
  •  | 
  •  

質問

私はそうのようなXPSドキュメントを表示するには、WPF DocumentViewerのコントロールを使用してきます:

viewer.Document = xpsDocument.GetFixedDocumentSequence();

ドキュメントビューア内の印刷ボタンをクリックすると、すべてのプリント大丈夫、印刷ジョブのしかし、名前が理想的であるSystem.Windows.Documents.FixedDocumentSequence、です。

どのようにして、印刷ジョブの名前を設定するのですか?

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

役に立ちましたか?

解決

私は解決策を見つけます。

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メソッドは発生しません。なぜ知ってはいけません。

他のヒント

私は同じ問題が私はうまく均等に働くの周りに別の仕事を見つけた私の状況では動作しません印刷コマンドを上書きしていた。

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);
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top