Xamarin Forms - Webview not showing up
Set the VerticalOptions
to FillAndExpand
and do the same for HorizontalOptions
if that's not working.
Probably the WebView
is getting a zero size height because when the layout happens the view is still empty.
So change the code in your WebPage.cs like this;
// ... Other code
public WebPage()
{
webView = new WebView
{
Source = "https://www.google.com",
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand
};
// toolbar
ToolbarItems.Add(new ToolbarItem("Back", null, () =>
{
webView.GoBack();
}));
Content = new StackLayout
{
Children = { webView }
};
}
// ... Other code
Another thing to consider: If you are responding to the WebView.Navigating event, be sure to not set its args.Cancel to true if the page loaded is the WevView.Source. The iOS implementation of WebView.Navigating fires when the WebView.Source is loaded but the Android implementation does not. If you set args.Cancel to true when the page in question is the WebView.Source, the WebView will be blank.