Frame and WebBrowser relationships

Source: Internet
Author: User

When the frame control navigates to HTML content, the frame control instantiates the local Webborwser ActiveX control internally. WPF enables security features by using feature control with WebBrowser ActiveX controls

So, in fact, when using frame in WPF to access a Web page, the frame contains something that is not a Web page, but a webbrowser, and then WebBrowser to revisit the page, which looks like nonsense, and it's not difficult to understand WebBrowser is still the basic carrier for web browsing.

But it's important to understand this when writing code, and it's very easy to overlook it.

When you use frame to access or call navigation or to load a Page object (XAML), it is straightforward and easy to understand that you can do something directly using the frame method, but there may be unexpected situations when you visit a Web page.

For example, when you use the loaded or LoadCompleted method of a frame, you will find that the Web page has not yet been loaded to complete these events. Loaded was executed at once, even at the beginning, and LoadCompleted was executed just as soon as the page was loaded.

Why this, it seems, is different from the description of the two events of frame, but there is no problem navigating the page (Xaml).


Read the detailed description of the method and the previous frame and WebBrowser relationship, can actually find out the answer.

Take the loaded event and the LoadCompleted event as an example.

The loaded event is available in almost all controls, so the loaded method of the frame is the same as the loaded of the other controls, and the control loads when it is finished.

LoadCompleted, this object is triggered when the frame content is loaded, it looks as if you can use this method to determine whether the page is loaded, but in fact, it is still not possible, why? If the frame is loaded with page (XAML), then this event is working, but when the page is loaded, as we said before, frame does not load the page directly, but creates a webbrowser, and then the WebBrowser loads the page, so When frame accesses a Web page, loadcompleted is created WebBrowser complete, not the page loaded.

So how do you tell if a page in a frame is loaded? Since frame does not load the page itself, but instead loads a webbrowser, and then loads the Web page by WebBrowser, we want to determine whether the page in the frame is loaded, but it is still handled by the methods and events in WebBrowser. This actually turns back to the previous WinForm operation.

So, when we use frame to load and interact with a Web page, we need to remember that there is a webbrowser,frame in the middle that just creates a webbrowser, and then WebBrowser completes the work. The loaded of frame is only triggered when it is finished by itself, loadcompleted event is WebBrowser instantiation, and the completion of Web page loading is the WebBrowser loadcompleted of triggering. Other cases follow this principle as well.

There is one more place to note that before frame triggers loadcompleted, frame is not yet completed WebBrowser created, so if you want the operation WebBrowser must be behind the loadcompleted, otherwise the exception will not be instantiated.

Don't use the WPF frame as a frame in a Web page.

Frame and WebBrowser relationships

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.