VansFannel
VansFannel

Reputation: 45921

WebBrowser control: show to user when it's navigating

I'm developing a Windows Phone application.

I'm using WebBrowser control and I want to show to users when is loading a page. I've used events:

private void Browser_Navigating(object sender, Microsoft.Phone.Controls.NavigatingEventArgs e)
{
    LoadingText.Visibility = System.Windows.Visibility.Visible;
}

private void Browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
    LoadingText.Visibility = System.Windows.Visibility.Collapsed;
}

But it doesn't work.

Any advice?

Upvotes: 2

Views: 1814

Answers (2)

johnhforrest
johnhforrest

Reputation: 991

Try using the LoadCompleted event:

private void Browser_LoadCompleted(object sender, NavigationEventArgs e)
{
    LoadingText.Visibility = System.Windows.Visibility.Collapsed;
}

This ensures that once everything is rendered the loading bar will disappear.

See the msdn page: http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.webbrowser.loadcompleted(v=VS.92).aspx

(I think Stuart was looking at the Windows Forms implementation of WebBrowser rather than the Phone Control)

Upvotes: 3

Stuart
Stuart

Reputation: 66882

I think your problem is in the navigated event - this

From msdn

Occurs when the WebBrowser control has navigated to a new document and has begun loading it.

This obviously could be long before the document is actually rendered.

I'm not sure there's any event to use to determine when the page is fully loaded and is rendered.

In iron7, I detect when the editor is loaded by using a timer - that timer keeps trying to call javascript methods in the script - I know these are only available after the document javascript ready occurs.

Upvotes: 3

Related Questions