目前,我正在为用户提供两个控件:保存和打印。当用户选择Save时,WPF显示的一个区域被打包并通过XpsDocumentWriter发送,并提示用户并鼓励用户签署新的xps文档。当用户选择“打印”时,PrintDialog.PrintVisual将相同区域打印到用户选择的打印机。
一切都很好,除了Microsoft XPS Document Writer是打印机的选择之一。有没有办法阻止或拦截用户选择XPS文档编写器并将它们发送到Save方法,以便我可以提示用户签署xps文档?
答案 0 :(得分:2)
免责声明:我之前从未使用过PrintDialog
,但看起来这样的事情可能有用:
System.Windows.Controls.PrintDialog printDialog = new PrintDialog();
if (printDialog.ShowDialog() == true)
{
PrintQueue selectedQueue = printDialog.PrintQueue;
if (selectedQueue.Name == "Microsoft XPS Document Writer")
{
// Run your XPS save & sign code
}
else
{
// Run your printDialog.PrintVisual() code
}
}
我真的不喜欢硬编码的打印机名称(我认为它因语言设置而异)。可能有PrintQueue
的更好属性,您可以使用它来识别此打印机。