[re-posted after a wiki malfunction]
There is much functionality of the native Web Browser control that our managed wrapper does not yet expose. The following code snippet [prepared with Matt G.] shows how to get the IWebBrowser2 interface from the WPF WebBrowser control. This allows access to methods on the object that are not publicly exposed in other ways for the control. Do note, however, that this code sample will only work in fully trusted code.
First, see IWebBrowser2 documentation here: http://msdn.microsoft.com/en-us/library/aa752127.aspx ...
To compile this code, add a COM Reference to System32\shdocvw.dll or ieframe.dll (whichever you have, depending on version of IE).
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("6d5140c1-7436-11ce-8034-00aa006009fa")]
internal interface IServiceProvider
{
[return: MarshalAs(UnmanagedType.IUnknown)]
object QueryService(ref Guid guidService, ref Guid riid);
}
static readonly Guid SID_SWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046");
...
IServiceProvider serviceProvider = (IServiceProvider)myWebBrowser.Document;
Guid serviceGuid = SID_SWebBrowserApp;
Guid iid = typeof(SHDocVw.IWebBrowser2).GUID;
SHDocVw.IWebBrowser2 myWebBrowser2 = (SHDocVw.IWebBrowser2) serviceProvider.QueryService(ref serviceGuid, ref iid);
...
And then myWebBrowser2 is ready for interaction.
You can also handle the native web browser's events (http://msdn.microsoft.com/en-us/library/aa768309(VS.85).aspx) through the generated managed wrappers, like this:
SHDocVw.DWebBrowserEvents_Event wbEvents = (SHDocVw.DWebBrowserEvents_Event)myWebBrowser2;
wbEvents.NewWindow += new SHDocVw.DWebBrowserEvents_NewWindowEventHandler(OnWebBrowserNewWindow);
void OnWebBrowserNewWindow(string URL, int Flags, string TargetFrameName, ref object PostData, string Headers, ref bool Processed)
{
// Set Processed to cancel opening of the new window.
}