Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

WebView does not always render

$
0
0

I am developing on a Nexus 5 with Android 4.4.3. I am trying to include a WebView in a few of my Pages. It seems like the WebView will only appear on every other Page in my Page Stack.

In GetMainPage method I have:

return new NavigationPage(new TestPage1());

TestPage1 is a TabbedPage and its constructor looks like this:

        public TestPage1()
        {
            var openTestPage2 = new Button {
                Text = "Open Test Page 2"
            };
            openTestPage2.Clicked += (object sender, EventArgs e) => Common.NavigateTo(Navigation, new TestPage2());

            var stacklayout = new StackLayout {
                Children = {
                    openTestPage2
                }
            };

            var contentPage = new ContentPage();
            contentPage.Content = stacklayout;
            this.Children.Add(contentPage);
        }

Clicking on the button opens TestPage2 (a ContentPage) in which the WebView DOES appear:

        public TestPage2()
        {
            var source = new HtmlWebViewSource();
            source.Html = @"<html><body>Test Page 2</body></html>";
            var webView = new WebView {
                VerticalOptions = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            webView.Source = source;

            var openTestPage3 = new Button {
                Text = "Open Test Page 3"
            };
            openTestPage3.Clicked += (object sender, EventArgs e) => Common.NavigateTo(Navigation, new TestPage3());

            Content = new StackLayout {
                Children = {
                    webView,
                    openTestPage3
                }
            };
        }

When I click on the button in TestPage2, TestPage3's WebView does NOT appear:

        public TestPage3()
        {
            var source = new HtmlWebViewSource();
            source.Html = @"<html><body>Test Page 3</body></html>";
            var webView = new WebView {
                VerticalOptions = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            webView.Source = source;

            Content = new StackLayout {
                Children = {
                    webView
                }
            };
        }

BTW, my Common.NavigateTo function looks like this:

        public async static void NavigateTo(INavigation n, Page targetPage)
        {
            await n.PushAsync(targetPage);
        }

Wondering if I am missing something that would prevent this type of erratic behavior. Thanks.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>