How to Use the SEDraftX Control in a WPF Application
Prolog
Designers who use custom programs for automating their routine design tasks that also need to interact with Solid Edge are constantly exploring newer platforms like the .Net based Windows Forms or ASP.Net and lately the new Windows Presentation Foundation or simply WPF.
Whereas hosting a Solid Edge ActiveX control like the SEPartX and SEDraftX are easily accomplished in a Windows Forms Application by drag-dropping from the Toolbox, the last installment by @ksbhadekar showed how to use these controls in a ASP.Net web application.
This article further shows how to use the Solid Edge SEDraftX control in a WPF application.
In this article:
- Prolog
- Obtaining the ActiveX Control Wrapper: The Easy Way
- Creating the ActiveX Control Wrapper: Under the Hood
- Hosting the ActiveX Control in a WPF Window
- Interacting with the ActiveX Control in WPF
- Tip-Tricks
- Epilog
Unlike a Windows Forms Application, the SEDraftX ActiveX control cannot be drag-dropped from the toolbox on to a WPF window. A wrapper is required to host a ActiveX control in WPF and there are two ways to obtain this wrapper.
Obtaining the ActiveX Control Wrapper: The Easy Way
The name is AxInterop.SEDRAFTXLib.dll and is readily available in the C:Program FilesSolid Edge STxProgram folder.
Note: [bulb .PNG] If you are interested in knowing how you can generate this wrapper to expand your knowledge base, continue reading, else skip to the section – Hosting the ActiveX Control on a WPF Page.
Creating the ActiveX Control Wrapper: Under the Hood
The procedure for generating the wrapper for any ActiveX control is amply detailed in this Microsoft knowledge article and in a nutshell, here’s the process for the Solid Edge SEDraftX control:
- Create a new Windows Forms Application.
- Add the SEDraftX control to the toolbox. To do this go to the General tab or any empty tab in the toolbox and right-click in the empty space in the tab. Then select Choose Items… from the context menu that appears.
- In the dialog that appears next, take the COM Components tab and scroll down to select the SEDraftX Control. Click OK.
- Drop the Solid Edge SEDraftX control on the Form:
- Build the project and open the output folder; note the AxInterop.SEDraftXLib.dll which is the wrapper generated for use in WPF:
Recollect from previous section, this is the same wrapper that comes readily with Solid Edge.
Hosting the ActiveX Control in a WPF Window
- Start a WPF Application and add a reference to SEDraftX.dll that was either built using the steps in previous section or the one directly in the Solid Edge Program folder.
- Add the namespace as shown below to the XAML part of the WPF project:
- Drop the special WindowsFormsHost from the Toolbox on to the WPF’s XAML Window and add the SEActiveX line as below:
Interacting with the ActiveX Control in WPF
The name MySEDraftX from XAML can be used in the code-behind using VB.Net or CSharp to access the properties of the SEDrfatX control as below:
Tip-Tricks
When the WPF window is resized, the Draft file graphics may not update with it.
To overcome this problem, use the Resize event of the WPF window as below:
Epilog
Windows Presentation Foundation or simply WPF is the latest development platform from Microsoft which is specifically released for a rich and polished user interface.
This in-depth and meticulously written article shows the various techniques to display Solid Edge Part, Draft and Assembly files with all its glitter and glory in the WPF UI.
The contents and code samples provided can be freely used as a knowledge base for all future developments projects that use WPF with Solid Edge.
~Tushar Suradkar
Solid Edge Users Facebook Group – Let’s Sync