Intercepting PrintDialog to XPS Document Writer

2k views Asked by At

Currently I am providing the user with two controls: Save and Print. When the user selects Save, a region of the WPF display is packaged up and sent through a XpsDocumentWriter and the user is prompted and encouraged to sign the new xps document. When the user selects Print, a PrintDialog.PrintVisual prints that same region to a user selected printer.

All well and good, except that Microsoft XPS Document Writer is one of the choices for printers. Is there a way to prevent or intercept the user selection of XPS document writer and send them to the Save method so I can prompt the user to sign the xps document?

1

There are 1 answers

1
Justin On BEST ANSWER

Disclaimer: I've never used PrintDialog before, but it looks like something like this might work:

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
    }
}

I don't really like having the printer name hard-coded (I assume it varies with language settings). Possibly there is a better property of PrintQueue that you can use to identify this printer.