An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
Hi @Jerry Bonetti ,
Thanks for reaching out.
The key point is: on Windows, don’t set the remote URL too early, wait until the WebView is fully initialized and attached to the UI.
In .NET MAUI, when you declare a WebView directly in XAML on the MainPage, it’s fully attached to the visual tree before the Source is applied, so navigation works as expected.
However, on Microsoft Windows, MAUI uses Microsoft Edge WebView2 under the hood. WebView2 is a bit stricter about lifecycle timing. If you dynamically create the WebView in C# and set the Source before:
- it’s added to the layout
- its handler is created
- or the control is fully loaded
then navigation may silently fail, and the Navigated event won’t fire.
Another approach you can consider is to ensure the control is fully added and loaded before setting the Source.
For example:
var webView = new WebView();
myLayout.Children.Add(webView);
webView.Loaded += (s, e) =>
{
webView.Source = "https://example.com";
};
Alternatively, if you're creating it inside a page lifecycle method, you can defer setting the Source until OnAppearing() or after confirming webView.Handler is not null.
Just a quick note, the snippet above is only a simplified example to demonstrate the concept. Depending on how your pages, layouts, or navigation are structured, you may need to adjust it slightly to fit your project.
Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well.