Open SinoAHpx opened 4 months ago
Just to clarify this happened to me on Windows (I did not test other platforms). Assigning Url
would also only navigate the first time.
Here's my workaround:
public static class WebViewHacks {
// https://github.com/MicroSugarDeveloperOrg/Avalonia.WebView/issues/63
[SupportedOSPlatform("windows")]
public static void Go(this WebView webView, Uri uri) {
if (!OperatingSystem.IsWindows())
throw new PlatformNotSupportedException();
webView.PlatformWebView!.Navigate(uri);
}
// https://github.com/MicroSugarDeveloperOrg/Avalonia.WebView/issues/63
[SupportedOSPlatform("windows")]
public static Uri? GetUri(this WebView webView) {
if (!OperatingSystem.IsWindows())
throw new PlatformNotSupportedException();
if (webView.PlatformWebView is null)
throw new InvalidOperationException();
if (webView.PlatformWebView is not WebView2Core platform)
throw new PlatformNotSupportedException(webView.PlatformWebView.GetType().FullName);
if (platform.CoreWebView2 is not { } coreWebView)
throw new InvalidOperationException();
return Uri.TryCreate(coreWebView.Source, UriKind.Absolute, out var uri) ? uri : null;
}
}
I have binded my
Url
property to a TextBox, but when I get Url changed inside the WebView, the Url property is not changed. For example, I setUrl
tohttps://google.com
initially, then I search random thing in google, apparently the "actual url" get changed, however theUrl
property will not be updated.