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