Andrew Sehr
Andrew Sehr

Reputation: 352

convert WPF WebBrowser to WinForms

I am trying to convert a WPF WebBrowser control to a WinForms WebBrowser control using this code:

System.Windows.Forms.WebBrowser wb = myWebBrowser as System.Windows.Forms.WebBrowser();

I am getting this error:

"Cannot convert type 'System.Windows.Controls.WebBrowser' to 'System.Windows.Forms.WebBrowser' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion"

Any help would be appreciated.

Thanks!

Upvotes: 0

Views: 1899

Answers (4)

Michel
Michel

Reputation: 282

You can't : they are 2 completely different class hierarchies (apparently both wrappers around an ActiveX component)

If you are desperate, you may try getting information through the Handle field, but this will put you in unmanaged land.

Upvotes: 0

Matěj Zábský
Matěj Zábský

Reputation: 17272

You can use ElementHost to add WPF System.Windows.Controls.WebBrowser to WinForms Form.

But I have no idea why you would want to do it.

Upvotes: 1

thor
thor

Reputation: 11

wpf and winforms controls are very different (apples and oranges) and can't be converted between each other.

Upvotes: 1

Reed Copsey
Reed Copsey

Reputation: 564373

You cannot convert between these two classes. They are completely separate implementations, one for WPF, and one for Windows Forms.

If you must use a Windows Forms WebBrowser, you'll need to instance one from scratch, and copy individual settings across as required.

Upvotes: 3

Related Questions