DocumentViewerのコントロールを使用するときにどのように私は、印刷ジョブの名前を設定するのですか?
-
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);
}
}
所属していません StackOverflow