![](/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.