From DWG to XAML (III)

Source: Internet
Author: User

. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.