Share via


DocumentViewer XPS Sample

The DocViewerXPS sample shows how to read and display an XML Paper Specification (XPS) document in a DocumentViewer control.

When executed, the sample displays a menu bar with a "File | Open..." option. When "Open..." is selected, a "File Open..." dialog is displayed allowing the user to browse and choose an XpsDocument file to open (a sample XML Paper Specification (XPS) document file is provided). When a document is opened, its content is displayed in the DocumentViewer control within the main application window.

The DocViewerXPS sample source code consists of four files:

  • App.xaml - XAML resources for the application (none in this sample).

  • App.xaml.cs - Code-behind for creating and displaying the application window.

  • Window1.xaml - XAML declarations defining the elements of the application window: main menu, menu commands, and DocumentViewer control.

  • Window1.xaml.cs - Code-behind supporting the user interface for the main menu commands.

A project file and sample XPS document are also provided. To examine the contents of the XPS document and the files contained within, simply change the document file extension from .xps to .zip and then open the file with the Zip utility.

This sample demonstrates a specific feature of the Windows Presentation Foundation (WPF) and, consequently, does not follow application development best practices. For comprehensive coverage of WPF and Microsoft .NET Framework application development best practices, refer to the following as appropriate:

Accessibility - Accessibility Best Practices

Security - WPF Security

Localization - WPF Globalization and Localization Overview

Download sample

Building the Sample

Procedure Title

  1. Install the Windows Software Development Kit (SDK) and open its build environment command window. On the Start menu, point to All Programs, Microsoft Windows SDK, and then click CMD Shell.

  2. Download the sample, usually from the software development kit (SDK) documentation, to your hard disk drive.

  3. To build the sample from the build environment command window, go to the source directory of the sample. At the command prompt, type MSBUILD.

  4. To build the sample in Microsoft Visual Studio 2005, load the sample solution or project file and then press CTRL+SHIFT+B.

Running the Sample

  • To run the compiled sample with debugging in Visual Studio 2005, press F5.

  • To run the sample from a CMD Shell command window, execute the .exe file located in the source folder of the sample.

See Also

Other Resources

Documents in Windows Presentation Foundation
DocumentViewer with Annotations XML-Store Sample
DocumentViewer with Annotations XPS Store Sample
Creating an XPS Document Sample
Saving an XPS Document Sample
Printing an XPS Document