在文档查看器中显示XPS文档

Sum*_*Guy 7 c# wpf documentviewer xps

我正在使用文档查看器和XPS atm,因为我之前没有尝试过.所以我有一段简单的代码加载XPS文档并在文档查看器中显示它,但是文档没有出现.文档查看器加载并在调试模式下快速一步,告诉我信息在那里,它只是不会显示.

        dvDoc = new DocumentViewer();

        string fileName = null;
        string appPath = System.IO.Path.GetDirectoryName(Assembly.GetAssembly(typeof(DocumentWindow)).CodeBase);

        if (type == "About")
            fileName = appPath + @"\Documents\About.xps";

        fileName = fileName.Remove(0, 6);
        XpsDocument doc = new XpsDocument(fileName, FileAccess.Read);

        dvDoc.Document = doc.GetFixedDocumentSequence();
Run Code Online (Sandbox Code Playgroud)

我能找到的所有文献都告诉我这样做,但它似乎对我不起作用.我知道文档查看器不喜欢URI,因此是filename.remove行.

关于我缺少什么的任何建议.

干杯,SumGuy

Cri*_*spy 10

你可能已经想到这一点,因为它已经差不多一个月了.

它看起来不像您的文档查看器是您的xaml文件的一部分.看起来您正在创建一个新的DocumentViewer对象,但从未将其添加到xaml文件中.

代替

dvDoc = new DocumentViewer();
Run Code Online (Sandbox Code Playgroud)

在你的xaml文件中声明它:

<DocumentViewer Name="dvDoc" />
Run Code Online (Sandbox Code Playgroud)

  • 我最近没有在这个特定的项目上工作过,所以我没有注意到.但是现在你提到它,很明显.欢呼回答 (2认同)