views:

1504

answers:

3

Hi:

I’m trying to run Google earth inside WPF but I don’t know how. Basically I have managed to run Google Earth in a Windows Form Control inside a Windows Form, everything was OK.

Trying to do the same thing in WPF, well, give strange result a small Google Earth screen placed anywhere in the form an not inside the User Control I have created, and there is now way to make this Google Earth Control grow, or shrink, when I grow or shrink the WPF Form.

Any help would be appreciated, I really mean any!

+2  A: 

If you have a Windows Forms control that already works exactly as you want, you could always use WindowsFormsHost to put that control on your WPF form. That might be the easiest thing to do... or is that what you're already doing that isn't working?

Grank
A: 

I found an walkthough about embedding Google Earth as an Control in a .Net WinForm. it's idea is like this, launche Google Earth application, then set your .Net WinForm Handle as google earth app's parent.

as you're porting this idea into a wpf app, you should do these code in a form loaded method. accourding to the docs from msdn, when a wpf window is ready to show, its loaded event is fired. so if you do this code in the constructor, you won't be able to get the winform handle.

but I got another problem here. as I emebed google earth as a control in either winform or wpfform, after the first launch of the application, googleearth.exe process will always exist, never quit. if I launch my app again, google earth control will never show in my app. is there anything that I missed? should I release reference to google earth as the app shuts down or something?

any advice is appreciated. thanks in advance

Allan Z.Tang
A: 

I also wrote an application that placed Google Earth inside a WinForms WebBrowserControl that was based on the more-or-less official example hosted by Google. It worked fine. I struggled to recreate the same application inside a WPF WebBrowserControl. My experience confirms what appears to be the general consensus that the WPF WebBrowserControl is harder to use because it provides less control. (e.g. With the WinForms WebBrowserControl you can use the properties to remove the scroll bar and eliminate the IE security question on startup, but with WPF WebBrowserControl you have to use kludges inside to HTML file loaded to get the same effect.) If you are following the Google GE plugin WinForms example, you have to move the JavaScript callback functions into a separate class because of WPF window cant be a parent of the .Net-COM interop between JavaScript and C#. Maybe the other artifacts you described are due to how you resolved this latter limitation. Before finding this solution, I was tempted to put the WinForms WebBrowser control inside the WPF window, but others have posted of unpleasing side-effects of doing this.

chetto