I am using webview for parsing my HTML data. For this, I am using a custom render.
In the Main Project:
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 Renderer
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)));
}
}
}
In XAML and XAML.cs:
<local:MyWebView
x:Name="web_view"
VerticalOptions="FillAndExpand"/>
web_view.Url = htmldata;
But I am getting System.ArgumentNullException
when running the project.
Screenshots: