Prod.: Engine, ver.: 6, ID: 60000924, HowTo : Using the VDF components in WPF projects

HowTo : Using the VDF components in WPF projects

Article60000924
TypeHowTo
ProductEngine
Version6
Date Added7/24/2009
Submitted byMatt
Keywords

Subject

Using the VDF components in WPF projects

Summary

How can I use the VDF components in Windows Presentation Foundation (WPF) projects ?

Solution

As you know the VDF components are Windows Forms components and not WPF components. So you will have to use a container in order to add a VDF component in your WPF application. This is a WindowsFormsHost container, see more information in MSDN.

You can create a new simple WPF sample in VS2008 C# (do not check Client-only Framework subset option) or in VS2010 C# (choose .NET Framework 4 and not .NET Framework 4 Client Profile), in the Window add some buttons and a WindowsFormHost control. In the first button click event use a code like :

public vdControls.vdFramedControl vdFramedControl1;  // Define a VDF component
public bool isCreated=false;

private void button1_Click(object sender, RoutedEventArgs e)
// Assign the vdFramedControl control as the host control's child.
   vdFramedControl1 = new vdControls.vdFramedControl();
   windowsFormsHost1.Child = vdFramedControl1;
   vdFramedControl1.BaseControl.ActiveDocument.OnAfterAddItem += new VectorDraw.Professional.vdObjects.vdDocument.AfterAddItemEventHandler(ActiveDocument_OnAfterAddItem);
// this events fires after an entity is added to the document
   isCreated = true;
} // this code can run in a event like WindowLoaded event.

and in the other button click event a code like :

private void button2_Click(object sender, RoutedEventArgs e)
{
   if (isCreated || (vdFramedControl1!=null))
   {
//draw some lines
      vdFramedControl1.BaseControl.ActiveDocument.CommandAction.CmdLine(null);
   }
   else MessageBox.Show("VDF Framed control isn't created");
}

And also add code for a simple event:

void ActiveDocument_OnAfterAddItem(object obj) // A VDF document event
{
   VectorDraw.Professional.vdPrimaries.vdFigure fig = (VectorDraw.Professional.vdPrimaries.vdFigure)obj;
   if (fig != null)
   {
      MessageBox.Show(fig._TypeName + " with handle : " + fig.Handle.ToString() + " created.");
   }
}

The first button will create a VDF Framed control inside the WindowsFormsHost and the second button will ask the user to draw some lines. With every line added to the document the event OnAfterAddItem will fire displaying the handle of the vdLine that was just created.

Make sure that the project has a license.licx file that contain the VDF component inside, in this project it should have a line like:

    vdControls.vdFramedControl, vdFramedControl, Version=6.1.6019.0, Culture=neutral, PublicKeyToken=54eac14e23c9ee53

This will "instruct" the Microsoft's license compiler (LC.EXE) to add to the application the necessary licensing information. The 6.1.6019.0 in the example above is the VDF version that is installed the development machine and in your case can alter. Make sure that the Licenses.licx file has in the Build Action property the value Embedded Resource.

Client Profile Frameworks 3.5 and 4, will not work with VDF components as System.Drawing.Design is not available to these frameworks