【发布时间】:2020-03-31 17:37:21
【问题描述】:
我正在使用 webview 来解析我的 HTML 数据。为此,我使用了自定义渲染。
在主项目中:
public class MyWebView : WebView
{
public static readonly BindableProperty UrlProperty = BindableProperty.Create(
propertyName: "Url",
returnType: typeof(string),
declaringType: typeof(MyWebView),
defaultValue: default(string));
public string Url
{
get { return (string)GetValue(UrlProperty); }
set { SetValue(UrlProperty, value); }
}
}
Ios 渲染器
public class MyWebViewRenderer : ViewRenderer<MyWebView, WKWebView>
{
WKWebView _wkWebView;
protected override void OnElementChanged(ElementChangedEventArgs<MyWebView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
var config = new WKWebViewConfiguration();
_wkWebView = new WKWebView(Frame, config);
SetNativeControl(_wkWebView);
}
if (e.NewElement != null)
{
Control.LoadHtmlString(Element.Url, null); //use this code instead
//Control.LoadRequest(new NSUrlRequest(new NSUrl(Element.Url)));
}
}
}
在 XAML 和 XAML.cs 中:
<local:MyWebView
x:Name="web_view"
VerticalOptions="FillAndExpand"/>
web_view.Url = htmldata;
但我在运行项目时收到System.ArgumentNullException。
截图:
【问题讨论】:
标签: xamarin.forms webview argumentnullexception