Goodday,
I want to replace the default WebView for iOS by WKWebView because of the bad performance, i took the example form the Xamarin website (hybridwebview). This works when i set the url when the app is initialising, it renders fast. In the example there is an event handler on Uri, but then i change the value by settings it the OnElementChanged is not fired?
Can somebody give me some advice or am i doing something terribly wrong? (I am new to Xamarin so sorry for silly questions )
Shared part:
<br />namespace Woby
{
public class HybridWebView : View
{
Action<string> action;
public static BindableProperty UriProperty = BindableProperty.Create(
propertyName: "Uri",
returnType: typeof(string),
declaringType: typeof(HybridWebView),
defaultValue: default(string));
public string Uri
{
get { return (string)GetValue(UriProperty); }
set { SetValue(UriProperty, value); }
}
}
}
Platform code (iOS):
<br />[assembly: ExportRenderer(typeof(HybridWebView), typeof(HybridWebViewRenderer))]
namespace Woby.iOS
{
public class HybridWebViewRenderer : ViewRenderer<HybridWebView, WKWebView>
{
protected override void OnElementChanged(ElementChangedEventArgs<HybridWebView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
var config = new WKWebViewConfiguration { };
var webView = new WKWebView(Frame, config);
SetNativeControl(webView);
}
if (e.OldElement != null){ }
if (e.NewElement != null)
{
if (Element.Uri != null)
{
Console.WriteLine("Changing = " + Element.Uri);
Control.LoadRequest(new NSUrlRequest(new NSUrl(Element.Uri)));
}
}
}
}
}