Geometry viewer with WPF

Instead of using the geometry viewer on a Windows Form as shown in this example, we look in this sample at using the geometry viewer for a WPF user interface. Therefore we create a new project "WPF Application" in Visual Studio. On the Main Window we place two controls, a button and a WindowsFormsHost, which we use to put our geometry viewer control into it. At the references we add CPlan.VisualObjects and CPlan.Geometry from the CPlan library. Furthermore we need to add OpenTK.dll and OpenTK.GL.Control.dll to our references. Either download it from the website or use the more comfortable way via NuGet Now, your project should look like this:

Next we add a few lines of code into the MainWindows.xaml.cs. Our geometry viewer will be placed into the WindowsFormsHost. Therefore we add a private variable myCamera:

private CPlan.VisualObjects.GLCameraControl myCamera;

After calling InitializeComponent() in the MainWindow method, we initialize myCamera in line 37 – 44. Afterwards we add test geometry to the viewer to see if it works.