I am trying to use a custom ContentView inside another page of my Xamarin Application. This custom ContentView is used for displaying HTML content (specifically gifs). When trying to load the ContentView from another page, it throws an error : "Value cannot be null. Parameter name thisActivity"
My code is based off the examples in here.
Am I missing a key step in getting a WebView to render via a custom ContentView?
//This is my Custom ContentView
public class GifView : ContentView
{
public GifView()
{
this.BuildPage();
}
public WebView BuildWebView()
{
var htmlSource = new HtmlWebViewSource
{
Html = @"<html><body><h1>This is a test</h1></body></html>"
};
WebView webView = new WebView
{
WidthRequest = 1000,
HeightRequest = 1000,
Source = htmlSource
};
return webView;
}
public void BuildPage()
{
var webView = this.BuildWebView();
this.Content = new StackLayout
{
Children =
{
webView
}
};
}
}
// This is the XAML where I am trying to use the custom view.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:myproject"
x:Class="myproject.MainPage"
xmlns:views="clr-namespace:myproject.Views">
<views:GifView />
</ContentPage>