Share via

WebView with remote url on windows not loading

Jerry Bonetti 5 Reputation points
2026-02-19T01:48:56.38+00:00

I have a Maui WebView that is not loading on Windows when its dynamically loaded.

If I create a webview with a url in source on the mainpage it works fine. But if I dynamically try to create a webview in c# deeper in the app, the url does not load and the Nagivate does not trigger.

Developer technologies | C#
Developer technologies | C#

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.

0 comments No comments
{count} vote

Answer recommended by moderator
  1. Jack Dang (WICLOUD CORPORATION) 14,955 Reputation points Microsoft External Staff Moderator
    2026-02-19T03:04:57.1433333+00:00

    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.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2026-02-19T01:49:37.92+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    When dynamically creating a WebView in a .NET MAUI application on Windows, there are a few things to consider that might affect the loading of the URL:

    1. Ensure Proper Initialization: Make sure that the WebView is properly initialized before attempting to set the Source. If the WebView is not fully constructed, it may not be able to load content correctly.
    2. Check for Height and Width Requests: If the WebView is contained within a layout such as HorizontalStackLayout, StackLayout, or VerticalStackLayout, ensure that you specify the HeightRequest and WidthRequest properties. If these properties are not set, the WebView may not render correctly, which could prevent the URL from loading.
    3. Use of Environment Variables: If your application is installed in a directory with restricted permissions (like Program Files), you may need to set the WEBVIEW2_USER_DATA_FOLDER environment variable to a writable location before initializing the WebView. This can be done in the App.xaml.cs constructor or in the platform-specific code for Windows.
    4. Debugging Events: Utilize the Navigating and Navigated events of the WebView to check if navigation is being triggered. You can log or debug these events to see if they are firing when you attempt to load the URL dynamically.
    5. Testing on Different Platforms: Since WebView uses different browser engines on each platform, ensure that your web content is compatible with the engine being used on Windows (WebView2 based on Microsoft Edge). Testing on all target platforms can help identify if the issue is specific to Windows.

    By addressing these points, you should be able to troubleshoot the issue with the WebView not loading the URL dynamically on Windows.


    References:

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.