Custom .NET Dockers in CorelDRAW X6

In the previous blog post we showed an example of a custom WPF control that was hosted in the UI of CorelDRAW. In this post we are going to take a Custom Web Docker that Hendrik had provided as an example and rewrite it as a Custom WPF .NET Docker. If you have never made a custom docker his article is a wonderful place to start. You may find it here: Custom add-ons and dockers in CorelDRAW

WPF User Control Library

Once again I will be using Visual Studio Professional. I will be posting all code samples this time in VB.NET as they were downloaded the most often in the last blog post. I will however include a C# version of the source code for those that prefer it.

To begin Open Visual Studio and Start a New Project | Visual Basic | Windows | WPF User Control Library. I named my project SM_Selection_VB, but feel free to name it whatever you like. Rename the UserControl1.xaml to Docker.xaml, double click on the Docker.xaml.vb and rename the public class UserControl1 to Docker. In the Solution Explorer right click your project name, in my case SM_Selection_VB and select add reference. If you have done the previous example the CorelDRAW interop assemblies will be listed in the Recent tab, if not the 64-bit location is:

You need to add a reference to both the Corel.Interop.CorelDRAW.dll and Corel.Interop.VGCore.dll. That should be it for setup we are all ready to get started coding.

XAML

Since we are creating a docker we will use the DesignHeight and DesignWidth, I have found that DesignWidth is best set to 225, and the height can be whatever fits your content best, in this case I went with a DesignHeight of 500.

Replace the Grid, with a StackPanel and then we can drag our needed labels, textboxes, and buttons from the Toolbox to our XAML, if you prefer you could of course type all the XAML by hand. I like to rename all the controls so they are easily identified. When you are done, you should have something that looks like the XAML below:

Visual Basic

Now that we are done with the XAML we need to code it up, this time we shall use Visual Basic. Again, keeping the code very basic, we have a Sub for each button that we created and our Sub for the SelectionChange event, you will only need WithEvents if you are listening for these types of events. All the selection of our shapes is done with a little CQL, which makes it very simple. When you are done, your code will look something like this:

Note: I did not post the full code due to space, if you want to see all the code please download the source files.

Save your work, and Build the solution to generate the .dll, I move the .dll to my Addons folder, but it can be placed anywhere you wish. Just remember where you put it because you will need to reference it in your VBA code.

Add Custom Docker

Adding the docker is very similar to adding or WPF Custom Control; expect that we will need a unique GUID to identify the docker by. You can generate a GUID from the tool included with Visual Studio, Create GUID, or if you prefer use an online tool such as: http://www.guidgenerator.com/ the important thing to remember is that you need to generate a new GUID for each new Custom .NET Docker you create.

The following VBA code, creates the docker in the UI, and makes an entry for our Docker in the Windows | Dockers menu.