How do I expose the LoadCompleted method in the WebBrowser class in WPF?

complete

Active member
Joined
Oct 24, 2012
Messages
25
Programming Experience
3-5
How do I expose the LoadCompleted method in the WebBrowser class in WPF C#?

I am trying to write a C# program in wpf that retrieves the content of a web page.

The first thing I tried was to try the WebRequest and WebResponse classes. This did not provide the actual displayed content. WebResponse reveils the HTML code that is sent to the browser. But I discovered that, while the page is being loaded by the browser, javascript can change what content is finally displayed in the browser.

So I decided to use the WebBrowser class.

Immediately I found that there are two WebBrowser classes. Thee is the one that is documented for WinForms and there is another that is documented for WPF. I need to understand the one documented for WPF. What I think I neeed to know what to do is to retrieve code after the "LoadCompleted" method is caused. But I do not know how to this and I cannot find any example demonstrating how this is done.
 
This doesn't really have anything to do with the LoadCompleted event. That event notifies you when a page has finished loading. That's all. The code to access the document in a WPF WebBrowser is exactly the same regardless of whether the document has just finished loading or it was loaded 10 minutes ago. This is a classic case of trying to solve the wrong problem and therefore not being able to find information on solving it.

Let me start by saying that I have almost never used a WebBrowser control in WinForms and never at all in WPF. Everything I know about the WPF WeBrowser control I have learned by doing research after reading your posts. It took me all of 30 seconds to find the LoadCompleted event after your last question and it hasn't taken me much longer to get the skinny on this one.

I know from past research that the WinForms WebBrowser has a Document property so I figured that the WPF version probably would too. Raeding the documentation bore that out, but it's not quite the same. It is declared as type Object, while the WinForms version is declared as type HtmlDocument. Again from research, I know that the HtmlDocument has a DomDocument property that is type Object, so a bit of intuition tells me that those two Object properties are probably directly, or fairly closely, equivalent.

If it was me, I'd find examples of working with that Document.DomDocument property of the WinForms WebBrowser and see if the same code would work with the Document property of the WPF WebBrowser. If it doesn't, I also found a couple of apparently relevant links using this obvious web search:

wpf webbrowser document - Bing

It's worth noting that it took me more time to type up this post than to find the information that it relays.
 
Back
Top Bottom