dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.96k stars 1.7k forks source link

WebView Source Binding does not update when navigating #13774

Open Guitarnivore opened 1 year ago

Guitarnivore commented 1 year ago

Description

Navigation is a bit inconsistent when using the WebView control.

Version with bug 7.0 (current)

Last working version Unknown

Reproduction

  1. Create default .NET MAUI project
  2. Create a View Model for your main page and create a UrlWebViewSource bindable property and set it as your Main Page's binding context.
  3. Add a Grid to the MainPage with a WebView, with its source bound to your UrlWebViewSource in your ViewModel, and a label bound to the Source's URL.
  4. Create events for Navigating and Navigated that log or similar so you can see when they fire.
  5. Play around to see inconsistency

OR

See attached reproduction ZIP. WebViewBinding.zip

ezgif com-optimize

Workaround?

You can update WebViewSource in the Navigating and/or Navigated event if the args URL does not match the WebViewSource URL, however as mentioned prior this does not always fire so is not a complete workaround.

Another workaround is not binding the WebView Source at all, and relying solely on the Navigating and Navigated methods.

ghost commented 1 year ago

Hi @Guitarnivore. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

Guitarnivore commented 1 year ago

Forgot to attach the zip, sorry!

WebViewBinding.zip

homeyf commented 1 year ago

Verified this issue with Visual Studio Enterprise 17.7.0 Preview 3.0(net8). Can repro on Windows platform with sample project. WebViewBinding.zip

mattleibow commented 10 months ago

Fir the first part, I do not believe the Source is supposed to change. The properties in the core library are read only so it is more a set and load vs a property to observe.

For the inconsistent events, this is an issue. I see in .NET 8 iOS now fires both events. Android still just fires Navigated. I need to test Windows again.

ghost commented 10 months ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.