0

我写了一个继承自 DocumentViewer 的类

public class MyDocumentViewer : DocumentViewer
{
    public bool Landscape{ get; set; }

    protected override void OnPrintCommand()
    {
        // get a print dialog, defaulted to default printer and default printer's preferences.
        PrintDialog printDialog = new PrintDialog();
        printDialog.PrintQueue = System.Printing.LocalPrintServer.GetDefaultPrintQueue();
        printDialog.PrintTicket = printDialog.PrintQueue.DefaultPrintTicket;

        // get a reference to the FixedDocumentSequence for the viewer.
        FixedDocumentSequence docSeq = this.Document as FixedDocumentSequence;

        // set the default page orientation based on the desired output.
        if(!Landscape)
            printDialog.PrintTicket.PageOrientation = System.Printing.PageOrientation.Portrait;
        else
            printDialog.PrintTicket.PageOrientation = System.Printing.PageOrientation.Landscape;

        if (printDialog.ShowDialog() == true)
        {
            // set the print ticket for the document sequence and write it to the printer.
            docSeq.PrintTicket = printDialog.PrintTicket;

            XpsDocumentWriter writer = System.Printing.PrintQueue.CreateXpsDocumentWriter(printDialog.PrintQueue);
            writer.WriteAsync(docSeq, printDialog.PrintTicket);
        }
    }

    protected override void OnManipulationBoundaryFeedback(System.Windows.Input.ManipulationBoundaryFeedbackEventArgs e)
    {
        base.OnManipulationBoundaryFeedback(e);
        e.Handled = true;
    }
}

我使用这个查看器来显示带有书签的 XPS 文件,在导航到书签后,文档将在标准 DocumentViewer 中重新加载。我知道如何在重新加载后更改样式,但我找不到解决此问题的方法。

是否可以更改 FixedDocument 的默认查看器?

如果没有,也许有人知道另一种解决方法。

4

0 回答 0