WebView2 control in a Dockpane

746
5
Jump to solution
05-26-2023 08:53 AM
BrianBulla
Occasional Contributor III

Hi,

I've added the Nuget for the most recent WebView2 control into my solutions, I add it to a ProDockpane, give it a source yet whenever I open the dockpane in ArcPro, the WebView control is always blank.

Any ideas as to where I might be going wrong?

<wv2:WebView2 Name="webView" Source="https://www.microsoft.com" />

 

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor
5 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor
BrianBulla
Occasional Contributor III

Perfect!  Thanks Wolf!

0 Kudos
BrianBulla
Occasional Contributor III

Hi @Wolf ,

So this is strange, and only started happening after implementing the Pro WebViewer.

In my AddIn, the user can choose to open the Uri that gets generated in a it's own web browser or directly in a dockpane (using the Pro WebViewer....which is working great).  But now that I have replaced the old Web Control I was using with the Pro WebViewer, when I try to open the same Uri in the system default web browser I get an error.

Do you think there is a connection to the new Pro WebViewer causing a conflict in the background??

This is the line that I get the error on:

System.Diagnostics.Process.Start(streetViewLink);

 

And here is the error....can't find the file specified???

BrianBulla_0-1685644515651.png

 

I've never had issues with this until I replaced the old Web Control with this new Pro WebViewer control.  Here is the code.

 

if (Properties.Settings.Default.svBrowserSetting == true)
                {
                    //*****Use this code if you want to open the separate web browser
                    string streetViewLink = @"https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=" + lat + "," + lng + "&Heading=";
                    System.Diagnostics.Process.Start(streetViewLink);        //opens the webbrowser 
                }
                else
                {
                    //Open the dockpane if it isn't already open
                    DockPane pane = FrameworkApplication.DockPaneManager.Find("StreetView_ArcPro_Dockpane");
                    pane.Activate();

                    //Access the web control through the View
                    DockpaneView myView = DockpaneView.MyDockpaneView;
                    Uri googleUri = new Uri(@"https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=" + lat + "," + lng + "&Heading=");                    
                    myView.webViewControl.Source = googleUri;
                }

 

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

@BrianBulla  When you call Process.Start () you have to change the defaults in ProcessStartInfo:

      Process.Start(new ProcessStartInfo
      {
        FileName = @"https://www.google.com/maps/@21.9000254,-159.5609088,3a,75y,15.95h,90t/data=!3m8!1e1!3m6!1sAF1QipMDaTpcy-_W_IIFOf9S5lc4L_nUhtu9nZ0H93Cm!2e10!3e11!6shttps:%2F%2Flh5.googleusercontent.com%2Fp%2FAF1QipMDaTpcy-_W_IIFOf9S5lc4L_nUhtu9nZ0H93Cm%3Dw203-h100-k-no-pi-8.217636-ya202.37381-ro0-fo100!7i6912!8i3456?entry=ttu",
        UseShellExecute = true
      });

The snippet worked for me.   I am not using a ProWindow with a web viewer 😉

If you don't use the ShellExecute option the default browser will only start if you give an html path.

BrianBulla
Occasional Contributor III

Ah yes....now I am remembering that when I take these projects that I am migrating from 2.9 to 3.0, that I also need to update some code here and there....and the Process.Start is definitely one of those sections.  I totally forgot about that, so thanks for the heads up!

 

0 Kudos