例外是:
System.MissingMethodException
Constructor on type 'MyApp.Droid.MyGridRenderer' not found
自定义渲染器:
using System;
using Android.Content;
using Android.Graphics;
using Android.Text;
using Android.Util;
using MyApp;
using MyApp.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(Grid), typeof(MyGridRenderer))]
namespace MyApp.Droid
{
public class MyGridRenderer : ViewRenderer<Grid, Android.Views.View>
{
protected MyGridRenderer(Context context) : base(context)
{
}
}
}
我有Visual Studio Community for Mac版本7.3.2
以防万一,这是iOS的自定义渲染器,没有任何构造函数正常工作:
using System;
using CoreGraphics;
using CoreText;
using Foundation;
using MyApp;
using MyApp.iOS;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(Grid), typeof(MyGridRenderer))]
namespace MyApp.iOS
{
public class MyGridRenderer : ViewRenderer<Grid, UIView>
{
}
}
Android自定义渲染器的构造函数的签名在Xamarin表单的最新版本(2.5.0)中更改为要求传递上下文。
You can see that here in the release notes.
这不是iOS所需要的。
尝试将protected更改为public。