コード例 #1
0
        private void WebBrowser_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
        {
            DotnetInterop = new WebViewPreviewDotnetInterop(Model, WebBrowser);

            WebBrowser.CoreWebView2.AddHostObjectToScript("mm", DotnetInterop);
            JsInterop = DotnetInterop.JsInterop;
            JsInterop.InitializeInterop();
        }
コード例 #2
0
        private void WebBrowser_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
        {
            // Assign interop objects for each request
            DotnetInterop = new WebViewPreviewDotnetInterop(Model, WebBrowser);
            JsInterop     = DotnetInterop.JsInterop;

            WebBrowser.CoreWebView2.AddHostObjectToScript("mm", DotnetInterop);
            DotnetInterop.InitializeInteropAsync().ConfigureAwait(false).GetAwaiter();
        }
コード例 #3
0
        async Task InitializeAsync()
        {
            // must create a data folder if running out of a secured folder that can't write like Program Files
            var browserFolder = Path.Combine(mmApp.Configuration.CommonFolder, "WebView_Browser");
            var env           = await CoreWebView2Environment.CreateAsync(
                userDataFolder : browserFolder
                );

            await WebBrowser.EnsureCoreWebView2Async(env);

            WebBrowser.NavigationCompleted += WebBrowser_NavigationCompleted;

            if (Model.Configuration.System.ShowDeveloperToolsOnStartup)
            {
                WebBrowser.CoreWebView2.OpenDevToolsWindow();
            }

            // Set up interop object to pass into JavaScript
            DotnetInterop = new WebViewPreviewDotnetInterop(Model, WebBrowser);
            JsInterop     = DotnetInterop.JsInterop;
            WebBrowser.CoreWebView2.AddHostObjectToScript("mm", DotnetInterop);
        }
コード例 #4
0
        async Task InitializeAsync()
        {
            // initial assignment of interop objects
            //DotnetInterop = new WebViewPreviewDotnetInterop(Model, WebBrowser);
            //JsInterop = DotnetInterop.JsInterop;

            var browserFolder = Path.Combine(mmApp.Configuration.CommonFolder, "WebView_Browser");
            // must create a data folder if running out of a secured folder that can't write like Program Files
            var env = await CoreWebView2Environment.CreateAsync(
                userDataFolder : browserFolder
                );

            await WebBrowser.EnsureCoreWebView2Async(env);

            if (Model.Configuration.System.ShowDeveloperToolsOnStartup)
            {
                WebBrowser.CoreWebView2.OpenDevToolsWindow();
            }

            // initialize here 'initially' then re-initialize for each navigation
            DotnetInterop = new WebViewPreviewDotnetInterop(Model, WebBrowser);
            JsInterop     = DotnetInterop.JsInterop;
        }
コード例 #5
0
 public WebViewPreviewJavaScriptInterop(WebViewPreviewDotnetInterop interop)
 {
     _webViewPreviewDotnetInterop = interop;
     WebBrowser = interop.WebBrowser as WebView2;
 }