Cefsharp - display page loading indication

时间:2016-02-12 19:44:50

标签: chromium-embedded cefsharp

I'm implemeting a win form which contains a cefsharp chromium-embedded browser.

I'm facing the following problem - sometimes it takes time until a page is loaded. The problem is that user has no idea that something happens until the page is actually loaded.

I have no control on the pages that the browser displays.

I need to display some kind of loading indication. I searched the web and the only thing that I found was to show an animated loading image while the loading takes place and hide it when the page is loaded (using the load state changed event). It seems to make things even slower.

Is there anything in Cefsharp infrastructure that I can use? or any other idea of solving it? Thanks!

2 个答案:

答案 0 :(得分:1)

ChromeView = new CefSharp.Wpf.ChromiumWebBrowser();
//Adding event listener
ChromeView.NavStateChanged += ChromeView_NavStateChanged;

//Event listener
private void ChromeView_NavStateChanged(object sender, CefSharp.NavStateChangedEventArgs e)
    {
        if(!e.IsLoading)
        {
            this.Dispatcher.Invoke(()=> { //Invoke UI Thread
                controller.setLoaderinBack(); //UI Update
            });
        }
        else
        {
            this.Dispatcher.Invoke(() => { //Invoke UI Thread
                    controller.setLoaderinFront(); //UI Update
            });
        }
    }

答案 1 :(得分:0)

对于CefSharp的更高版本(Mine版本81):

ChromeView = new CefSharp.Wpf.ChromiumWebBrowser();
//Adding event listener
ChromeView.LoadingStateChanged += ChromeView_NavStateChanged;

//Event listener
private void ChromeView_NavStateChanged(object sender, LoadingStateChangedEventArgs e)
    {
        if(!e.IsLoading)
        {
            //Stuff...
        }
        else
        {
            //Stuff...
        }
    }