![](/img/trans.png)
[英]Xamarin.forms cannot convert from object to system.type with Xamarin.Auth and specific android platform
[英]How to convert Xamarin.Forms WebView object to platform-specific WebView object?
我在Xamarin.Forms中创建了一个WebView对象:
WebView webView = new WebView {
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
};
我需要对该对象执行一些特定于平台的操作:调用Xamarin.Forms中不可用的一些函数,因为此特性在不同平台上不同。
问题是,当我传递Xamarin.Forms对象时:
public interface IWebViewCallCSharp
{
void passWebView(WebView webView);
}
我可以在“本机方面”执行与Xamarin.Forms中完全相同的操作。 如何在每个平台上获得某些特定于平台的WebView功能? 如何转换这个来此 ?
您将需要实现一个所谓的自定义渲染器。 从这里开始: 实现HybridWebView 。
简而言之,您将需要:
在最后一步中,您需要
开始使用本机控件的起点是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.