Skip to content

Commit 8d02b8a

Browse files
[Automated] Sync v.next with main (#1688)
Co-authored-by: Ian Malcolm <[email protected]>
1 parent ad59896 commit 8d02b8a

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

src/Directory.Packages.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<PackageVersion Include="Esri.ArcGISRuntime.Toolkit.WinUI" Version="$(ArcGISMapsSDKVersion)" />
1515
<PackageVersion Include="Esri.Calcite.Maui" Version="0.1.0-preview1" />
1616
<PackageVersion Include="Markdig" Version="0.37.0" />
17+
<PackageVersion Include="Microsoft.Web.WebView2" Version="1.0.3537.50" />
1718
<PackageVersion Include="System.Text.Json" Version="9.0.2" />
1819
<PackageVersion Include="System.Speech" Version="8.0.0" />
1920
<PackageVersion Include="System.Drawing.Common" Version="8.0.6" />
@@ -31,4 +32,4 @@
3132
<PackageVersion Include="Microsoft.Maui.Controls.Compatibility" Version="9.0.21" />
3233
<PackageVersion Include="Xamarin.AndroidX.AppCompat" Version="1.7.0.4" />
3334
</ItemGroup>
34-
</Project>
35+
</Project>

src/WPF/WPF.Viewer/ArcGIS.WPF.Viewer.Net.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>WinExe</OutputType>
44
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
@@ -61,6 +61,7 @@
6161
<PackageReference Include="Esri.ArcGISRuntime.Toolkit.WPF" />
6262
<PackageReference Include="Esri.ArcGISRuntime.WPF" />
6363
<PackageReference Include="Markdig" />
64+
<PackageReference Include="Microsoft.Web.WebView2" />
6465
<PackageReference Include="System.Speech" />
6566
</ItemGroup>
6667
<ItemGroup>

src/WPF/WPF.Viewer/Helpers/ArcGISLoginPrompt.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
// language governing permissions and limitations under the License.
99

1010
using Esri.ArcGISRuntime.Security;
11+
using Microsoft.Web.WebView2.Core;
12+
using Microsoft.Web.WebView2.Wpf;
1113
using System;
1214
using System.Collections.Generic;
1315
using System.Threading.Tasks;
1416
using System.Windows;
15-
using System.Windows.Controls;
16-
using System.Windows.Navigation;
1717
using System.Windows.Threading;
1818

1919
namespace ArcGIS.Helpers
@@ -115,18 +115,17 @@ public Task<IDictionary<string, string>> AuthorizeAsync(Uri serviceUri, Uri auth
115115
// Challenge for OAuth credentials on the UI thread.
116116
private void AuthorizeOnUIThread(string authorizeUri)
117117
{
118-
// Create a WebBrowser control to display the authorize page.
119-
WebBrowser webBrowser = new WebBrowser();
118+
// Initialize a WebView2 control to display the authorize page.
119+
WebView2 webBrowser = new WebView2() { MinWidth = 500, MinHeight = 500 };
120120

121121
// Handle the navigation event for the browser to check for a response to the redirect URL.
122-
webBrowser.Navigating += WebBrowserOnNavigating;
122+
webBrowser.NavigationStarting += WebBrowserOnNavigationStarting;
123123

124124
// Display the web browser in a new window.
125125
_authWindow = new Window
126126
{
127127
Content = webBrowser,
128-
Width = 450,
129-
Height = 450,
128+
SizeToContent = SizeToContent.WidthAndHeight,
130129
WindowStartupLocation = WindowStartupLocation.CenterOwner
131130
};
132131

@@ -136,9 +135,15 @@ private void AuthorizeOnUIThread(string authorizeUri)
136135
_authWindow.Owner = Application.Current.MainWindow;
137136
}
138137

139-
// Handle the window closed event then navigate to the authorize url.
138+
// Handle window loaded event as the WebView2 control can only be initialized after it is visible in the UI
139+
_authWindow.Loaded += async (s, e) =>
140+
{
141+
await webBrowser.EnsureCoreWebView2Async();
142+
webBrowser.CoreWebView2.Navigate(authorizeUri);
143+
};
144+
145+
// Handle the window closed event
140146
_authWindow.Closed += OnWindowClosed;
141-
webBrowser.Navigate(authorizeUri);
142147

143148
// Display the window.
144149
_authWindow.ShowDialog();
@@ -163,17 +168,16 @@ private void OnWindowClosed(object sender, EventArgs e)
163168
_authWindow = null;
164169
}
165170

166-
// Handle browser navigation (content changing).
167-
private void WebBrowserOnNavigating(object sender, NavigatingCancelEventArgs e)
171+
// Handle browser navigation
172+
private void WebBrowserOnNavigationStarting(object sender, CoreWebView2NavigationStartingEventArgs e)
168173
{
169174
// Check for a response to the callback url.
170175
const string portalApprovalMarker = "/oauth2/approval";
171-
WebBrowser webBrowser = sender as WebBrowser;
172176

173-
Uri uri = e.Uri;
177+
Uri uri = new Uri(e.Uri);
174178

175179
// If no browser, uri, or an empty url, return.
176-
if (webBrowser == null || uri == null || string.IsNullOrEmpty(uri.AbsoluteUri))
180+
if (sender == null || uri == null || string.IsNullOrEmpty(uri.AbsoluteUri))
177181
return;
178182

179183
// Check for redirect.

0 commit comments

Comments
 (0)