wpf继承了DocumentViewer和Frame Navigation

时间:2014-06-27 12:47:45

标签: c# wpf inheritance documentviewer navigationservice

我写了一个继承自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的默认查看器?

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

0 个答案:

没有答案