LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can you use WPF in a .NET Container in LabVIEW?

Is it possible to put a WPF control in a .NET container?  We are trying but the assembly (dll) always says there are no public controls.

 

John

0 Kudos
Message 1 of 14
(7,423 Views)

There is currently no support for WPF in LabVIEW. You could post an idea in the LabVIEW Idea Exchange.

0 Kudos
Message 2 of 14
(7,414 Views)

I believe you have to wrap the WPF control in a windows form. Then you can insert it into a .NET container.

Jarrod S.
National Instruments
0 Kudos
Message 3 of 14
(7,383 Views)

Hi Jarrod,

 

Does the latest LabView 2012 support WPF control now? Or I still have to wrap the WPF control in a windows form?

 

Thanks

 

Daniel Hou

0 Kudos
Message 4 of 14
(7,053 Views)

Daniel

 

There is still no native support for WPF in LabVIEW.  The most recent release of Measurement Studio has added support for WPF, but as of yet, no decision has been made as to whether or not it will be added in future versions of LabVIEW.  As always, you can make a feature request on the LabVIEW Idea Exchange.

 

For now, you should still be able to wrap your control in a Windows Form and add it in a .NET Container.

 

0 Kudos
Message 5 of 14
(7,031 Views)

I am attempting to host a WPF control in a Windows Forms app. Outside LabVIEW, using a .Net test client, everything seems to work fine. However, when I attempt opening this form in LabVIEW, we receive an Error 1172 indentifying that it needs to be a STA.

 

I have, or so I thought, made this a STA with the following approach using TaskScheduler and Task. However, I am receiving the same error. Is there some specific approach that LabVIEW requires for this to work?

 

public void DisplayForm()
        {
            try
            {
                TaskScheduler taskUI = TaskScheduler.FromCurrentSynchronizationContext();
 
                Task deploymentTask = Task.Factory.StartNew(() =>
                {
                    this._wpfControlHost.OnReadyToTest += this._wpfControlHost_OnReadyToTest;
 
                    this._wpfControlHost.ShowDialog();
                    this._wpfControlHost.BringToFront();
 
                },CancellationToken.None, TaskCreationOptions.LongRunning, taskUI);                
            }
            catch (Exception ex)
            {
                // ToDo: 
                // Log
                // Present user with error message
            }           
        }
0 Kudos
Message 6 of 14
(6,967 Views)

Because WPF does not natively speak to LabVIEW it appears that you want to wrap the WPF control into a .NET I'm not 100% sure this will work but here are some useful web pages.

 

These two would be best to read first, they describe how LabVIEW interacts with .NET

 

https://www.ni.com/docs/en-US/bundle/labview/page/using-net-with-labview.html

 

https://www.ni.com/docs/en-US/bundle/labview/page/loading-net-assemblies.html

 

These will give you a good idea of what is needed to make this work.

 

http://msdn.microsoft.com/en-us/library/ms182351(v=vs.80).aspx

 

http://www.blayd.co.uk/article.aspx?pageid=1014

 

I'm not super familiar with WPF but good luck and I encourage others to help because this is an interesting application to say the least.

Ryan
Applications Engineer
National Instruments
0 Kudos
Message 7 of 14
(6,942 Views)

Ryan,

   Thanks for the info. Just so you are aware, this is a Windows Forms app hosting the WPF control. Some of the posts above indicated this would be the way to go. So, I think I am on the right path, there is just the STA issue that I am attempting to resolve at this point.

 

   I'll take a look at the links you sent. Perhaps they will help.

 

Regards,

Chad

0 Kudos
Message 8 of 14
(6,936 Views)

Could you state exactly the phrase of the error that is showing up? Is this an error in LabVIEW or Windows?  I might be able to look up this error and give you further troubleshooting. 

Ryan
Applications Engineer
National Instruments
0 Kudos
Message 9 of 14
(6,921 Views)

I don't have the exact phrase at the moment. I can get it from the LabVIEW guy...I'm the .Net guy.

 

In the meantime it's, Error 1172, Something about a Single Threaded Apartment and that some UIs require that.

 

Similar to this:

The calling thread must be STA, because many UI components require this.) <append><b>System.InvalidOperationException</b>

 

Thanks,

Chad

0 Kudos
Message 10 of 14
(6,908 Views)