开发者

How to access Document object same like WebBrowser control with WebView2 in WPF?

In my project we were using WebBrowser control and it has print html functionality implemented by using below code, as you all know IE is no more supported I am replacing WebBrowser control with WebView2 in my WPF application.

 IOleServiceProvider sp = webBrowser1.Document as IOleServiceProvider;
            if (sp != null)
            {
                Guid IID_IWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046");
                Guid IID_IWebBrowser2 = new Guid("D30C1661-CDAF-11d0-8A3E-00C04FC9E26E");
                const int OLECMDID_PRINT = 6;
                const int OLECMDEXECOPT_DONTPROMPTUSER = 1;

                dynamic wb; // will be of IWebBrowser2 type, but dynamic is cool

                sp.QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, out wb);
                if (wb != null)
                {

                    wb.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, null, null);

                }
            }

When I replaced the WebView2 and try to achieve the same functionality, I replaced the above code with webBrowser1.ExecuteScriptAsync("window.print();"). Unable to achieve the same and there is no Docum开发者_Go百科ent object associated the WebView2.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜