Tuesday, May 8, 2012

WPF Browser Application–Visio Viewer

I decided to follow up my previous article on Embedding Visio in a WPF Browser Application by taking a look at what can be done with the Visio Viewer.  Let’s start out like we did before with a WPF Browser Application:

2012-05-01_2246

and add your reference to the WindowsFormsIntegration part:

2012-05-01_2347

and open up a Visual Studio Command Prompt (2010) and make your Interop assembly, this time from the VVIEWER.DLL (I found mine in C:\Program Files (x86)\Microsoft Office\Office14) using the command:

aximp VVIEWER.DLL

This time, two dlls are created: AxVisioViewer.dll and VisioViewer.dll.  We are only going to be using AxVisioViewer.dll at this time, so add your reference:

2012-05-04_1551

You then drop your WindowsFormsHost on the panel or add the following in the xaml:

<WindowsFormsHost HorizontalAlignment="Stretch" Name="windowsFormsHost1" VerticalAlignment="Stretch" />

Add a line to your class for an instance of the AxViewer:


private AxViewer visioControl = new AxViewer();

and then update the constructor for the page to add the control to the WindowsFormsHost:



this.windowsFormsHost1.Child = this.visioControl;


add an event handler for the page loaded event and drop in a line to load your Visio document:


this.visioControl.SRC = @"http://smithmier.com/Visio/TestDrawing.vsd";

and finally, update your project security to a Full Trust Application on the solution properties screen:


2012-05-08_1519


Notice the difference?  Go ahead, look back.  I will wait.


Find them?  AxDrawingControl becomes AxViewer and .Src becomes .SRC.  That is all.


Of course, there are many other things that changed, but in the very simple example code it isn’t apparent.  The two main differences for end users is that they won’t need Visio installed to view the document with this version, and they won’t be able to alter the document in this version.  I will go through the changes in the object model and control available in future posts.


Source code: VisioViewerWPF.zip

3 comments:

  1. Larry,
    Can you also upload the code with this post?

    ReplyDelete
  2. Sure, the source has been added to this and the previous one.

    ReplyDelete