Display an XPS document in the document viewer

I have a document viewer and XPS atm since I have not tried this before. Therefore, I have a simple piece of code that downloads an XPS document and displays it in the document viewer, but the document does not appear. The document viewer loads, and a quick switch to debug mode tells me that there is information, it just does not appear.

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(); 

All the literature I can find tells me to do it this way, but for me it doesn't seem to work. I know that the document viewer does not like URIs, therefore filename.remove line.

Any suggestions regarding what I am missing.

Cheers, SumGuy

+6
c # wpf xps documentviewer
source share
1 answer

You probably already understood this, because almost a month has passed.

It doesn't seem like your document viewer is part of your xaml file. It looks like you are creating a new DocumentViewer, but never adding it to the xaml file.

Instead

 dvDoc = new DocumentViewer(); 

Declare it in your xaml file:

 <DocumentViewer Name="dvDoc" /> 
+9
source share

All Articles