Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use ActiveX ComponentWorks 3D graph in NI WPF application?

Hello,

 

I would like to display data in a 3D graph in my NI WPF application. It is my understanding that there is not a WPF 3D graph I can use out of the Visual Studio Toolbox that I can just drop into the designer (i.e. DigitalGraph, Graph, IntensityGraph, etc.). After doing some research I learned that NI has a ActiveX ComponentWorks 3D graph that can be added into WinForm applications fairly easily. However, I know that it is possible to host ActiveX controls in WPF applications so that is what I have been trying to do. So far I have not been successful.

 

Before I began writing the code shown below I found some NI WinForm sample applications online to figure out what references I needed to use the 3D graph and how to interact with it. I found that in order to use the CWGraph3D Control the following references are needed (and maybe some other references from the System namespace I am forgetting).

  • AxCW3DGraphLib
  • CW3DGraphLIb

I figured that if I could add these references to my NI WPF application, then I could add the ActiveX 3D graph to my view programmatically. To get a copy of these references, I created a new NI WinForm application, added the CWGraph3D control to the Toolbox, added the graph to the application's form, and built the solution. Doing so produced 2 DLL's of interest underneath the project's bin directory, specifically AxInterop.CW3DGraphLib.dll and Interop.CW3DGraphLib.dll.

 

I copied these assemblies to my NI WPF application's lib directory and added references to them from the Visual Studio Solution Explorer. From here I was able to begin writing code to host the ActiveX control inside my WPF application (intellisense was even working with it).

 

The XAML view I am attempting to host the ActiveX control in contains a stack panel.

<StackPanel x:Name="RaControlContainer">
    <TextBlock x:Name="RaTitle" FontSize="20"/>
</StackPanel>

Next is the code behind for given XAML view.

private AxCWGraph3D _graph;
public RaView()
{
    InitializeComponent();
    Loaded += OnLoaded;
}
private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
    var host = new WindowsFormsHost();
    _graph = new AxCWGraph3D();
    host.Child = _graph;
    RaControlContainer.Children.Add(host);
}

I can build my solution without error and the WPF application runs fine as long as I don't attempt to activate the RaView (done with a button click). When I attempt to activate the RaView, the following exception is thrown...

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in WindowsBase.dll

Additional information: Could not load file or assembly 'Interop.CW3DGraphLib, Version=1.6.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

I haven't been able to figure out why this exception is being thrown. I am a little bit baffled at this error because I know the Interop.CW3DGraphLib.dll exists in the directory where it is being referenced from. I would like to mention that this exception is thrown after the RaView() constructor is called and before the OnLoaded event handler is executed. 

 

I am not sure what the problem is here, any suggestions/help is appreciated!

0 Kudos
Message 1 of 3
(3,049 Views)

Showing data in my application in a 3D graph is no longer required. Please disregard!

0 Kudos
Message 2 of 3
(3,028 Views)

Someone please regard, because I have the same question.

 

Same situation except I want a 

 

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
   // Create the interop host control.
   System.Windows.Forms.Integration.WindowsFormsHost host =
        new System.Windows.Forms.Integration.WindowsFormsHost();

   

   CW3DGraphLib.CWGraph3D pc3d = new CW3DGraphLib.CWGraph3D();

 

   host.Child = pc3d;

 

   this.GraphGrid.Children.Add(host);
}

 

The error says that host.Child can't assign this type because it needs explicitly cast, but can't seem to find a type to cast it to.

 

0 Kudos
Message 3 of 3
(1,847 Views)