2
votes

I have a WebView that shows the terms and conditions when the user starts the app. That WebView contains a few links. Currently, I have the terms and conditions as a html file that I store in resources.

In the code-behind I fill the WebView via:

public partial class Agb : ContentPage
{
    public Agb()
    {
        InitializeComponent();
        BindingContext = new ViewModel.AgbViewModel();

        Web.Source = new HtmlWebViewSource
        {
            Html = Properties.Resources.Agb
        };

        Web.Navigating += WebViewNavigating;
    }

XML:

        <WebView 
            x:Name="Web" 
            VerticalOptions="FillAndExpand" 
            Margin="50,0"/>

Most of the time this works well. On UWP this WebView sometimes fails to show. It always shows on my own computer but randomly fails in production.

Is there anything I can do to get the WebView to work reliably?

1
Please share a stable reproduce code sample for us. - Nico Zhu - MSFT
@NicoZhu-MSFT : Unfortunately, I don't know how to reproduce the bug. I just know that it sometimes happens in production. With a bit of googling I found xamarin.github.io/bugzilla-archives/57/57451/bug.html . - Christian
Do you means it is known issue in xamarin? - Nico Zhu - MSFT
@NicoZhu-MSFT : I'm not sure to what extend they see it as "known". It's on the old bugzilla and there doesn't seem to be an issue on Github currently when I search 57451 (the bugzilla error code). It might also be a forgotten issue. From reading the bug report it's also not clear to me whether the issue resides in Xamarin or UWP. - Christian

1 Answers

1
votes

Option 1:

I've made a pull request to fix this bug in Xamarin.Forms, so simply update Xamarin.Forms to a version, where it will be merged.

However, while the fix is not yet there and while the fix may not be available for earlier versions of Xamarin.Forms before 4.4.0, here's how to fix it in your project:

Option 2

Add the WebViewRenderer_fix.cs file to your project. This file is based on v4.4.0, but if you see build errors, you may need to apply the fix yourself to earlier version of this file.

And don't forget to register it as a custom renderer for your WebView

[assembly: ExportRenderer(typeof(WebView), typeof(WebViewRenderer_fix))]