[英]How to convert Xamarin.Forms WebView object to platform-specific WebView object?
I have a WebView object created in Xamarin.Forms: 我在Xamarin.Forms中创建了一个WebView对象:
WebView webView = new WebView {
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
};
I need to do some platform-specific operations on this object: call some functions that aren't available in Xamarin.Forms because of different nature of this on different platforms. 我需要对该对象执行一些特定于平台的操作:调用Xamarin.Forms中不可用的一些函数,因为此特性在不同平台上不同。
The problem is, when I pass the Xamarin.Forms object: 问题是,当我传递Xamarin.Forms对象时:
public interface IWebViewCallCSharp
{
void passWebView(WebView webView);
}
I can do on "native side" exactly the same things as I could in Xamarin.Forms. 我可以在“本机方面”执行与Xamarin.Forms中完全相同的操作。 How can I get some platform-specific functions of WebView on each platform?
如何在每个平台上获得某些特定于平台的WebView功能? How to convert this to this ?
如何转换这个来此 ?
You will need to implement a so-called custom renderer. 您将需要实现一个所谓的自定义渲染器。 Start here: Implementing a HybridWebView .
从这里开始: 实现HybridWebView 。
In short you will need to: 简而言之,您将需要:
In the last step you need to 在最后一步中,您需要
The starting point where you begin using native controls is the OnElementChanged
override. 开始使用本机控件的起点是
OnElementChanged
覆盖。
protected override void OnElementChanged (ElementChangedEventArgs<NativeListView> e)
{
base.OnElementChanged (e);
if (Control == null) {
// Instantiate the native control and assign it to the Control property
}
if (e.OldElement != null) {
// Unsubscribe from event handlers and cleanup any resources
}
if (e.NewElement != null) {
// Configure the control and subscribe to event handlers
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.