【发布时间】:2019-02-11 00:13:22
【问题描述】:
我正在尝试在我的 Xamarin 应用程序的另一个页面中使用自定义 ContentView。此自定义 ContentView 用于显示 HTML 内容(特别是 gif)。尝试从另一个页面加载 ContentView 时,会抛出错误:“Value cannot be null.Parameter name thisActivity”
我的代码基于here 中的示例。
我是否错过了通过自定义 ContentView 呈现 WebView 的关键步骤?
//这是我的自定义内容视图
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
}
};
}
}
// 这是我尝试使用自定义视图的 XAML。
<?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>
【问题讨论】:
标签: xamarin xamarin.forms