. The implementation of XPS packaging class Library and a Dwfx packaging class library in net
DocumentViewer
In fact, complex things can be very simple. The wheel you want, maybe someone else has already built it for you. The same is true here. For example, all you want is to view DWG files directly at the front of your system, so all you need to do is simply export from DWG to dwfx files, and then use the WPF DocumentViewer control to open the file. This sample program can be obtained from here.
Xaml
1. <documentviewer name= "Docviewer"/>
Code-behind:load DWFX
1. xpsdocument xpsdocument = null;
2.
3. if (dlg. ShowDialog () = = System.Windows.Forms.DialogResult.OK)
4. {
5.//If There ' s an existing document open, close it.
6. If (xpsdocument!= null)
7. Xpsdocument.close ();
8.
9.//Create an xpsdocument for the "file specified by the" user.
Try
11. {
XpsDocument = new
XpsDocument (dlg. FileName, System.IO.FileAccess.Read);
14.}
catch (UnauthorizedAccessException)
16. {
System.Windows.MessageBox.Show (
String.Format ("Unable to access {0}", dlg.) FileName));
return;
20.}
21st.
/For optimal performance the XPS document should is remain
FixedDocumentSequence//Open while it is active in the
//DocumentViewer control. When the XPS document is opened
//With the XpsDocument constructor ("New XpsDocument" above) a
num//reference to it are automatically added to the PackageStore.
The//The Packstore is a static application collection that contains
The//a reference to each open package along the package ' s URI as
The.//a key. Adding a reference of the XPS package to the
//PackageStore keeps the package open and avoids repeated opens
The//and closes while the document content are being accessed by
//DocumentViewer control. The Xpsdocument.dispose () method
Removes//automatically the package from the PackageStore
The document is removed from the DocumentViewer control and
The.//is no longer in use.
Docviewer.document = Xpsdocument.getfixeddocumentsequence ();
DocumentViewer is a control that WPF specifically prepares to render the contents of an XPS file. What it renders is called FixedDocument, which fully conforms to the XPS standard. Our DWFX format files are compatible with XPS, so they can also be loaded and displayed directly by DocumentViewer. We use DocumentViewer to open a dwfx file and carefully contrast it, you will send Now it appears in the content and in AutoCAD exactly the same.