Trying to use the WPF Usercontrol inside multiple forms

Mar 18, 2009 at 9:42 AM

I'm trying to host the VE wpf control inside a elementhost inside a regular windows form.
This works perfectly, but when i try to re-open the form or open a new form containing the usercontrol, i get following exception:

Object reference not set to an instance of an object.

on line:

this.globeControl.Host.DataSources.Add(new DataSourceLayerData("Elevation", "Elevation",

Apparently the Host's Datasources is null.
Am I doing something wrong or do you have any idea on how to make this run right?
I can provide a demo project to illustrate my problem if required.



Mar 18, 2009 at 1:42 PM

The native VE3D control is Win32 based.  Why not just use the Win32 GlobeControl?  Then you wouldn't have to deal with WPF->Win32 interop.  The whole challenge of this particular project was taking the native Win32 control and getting around Win32->WPF interop issues.  It seems like a lot of trouble to go Win32->WPF->Win32!

Take a look here for how to use the Win32 GlobeControl.

The null Host or DataSources error occurs when the backend VE3D control has not been initialized and/or shown.  I'm not quite sure when you are saying it works or doesn't.  The first time you open the form it works, but when you close it does it close it before re-opening just one window or the whole application?  Are you trying to open two instances of the window?

Note that due to technical limitations inside the Virtual Earth 3D control itself, there can only be one instance per process.  (This is true for VE3D in the browser as well.)

When the exception occurs, try looking in the debugger at whether the VEMap.winVE is null and whether VEMap.globeControl is null.