我正在使用我需要在Xamarin表单中为CustomCollectionViewRenderer创建自定义控件,因为我需要在Xamarin表单中显示诸如Pinterest应用之类的图像集合。但是没有[[OnElementChanged可以覆盖CollectionViewRenderer。我在这里做错什么了吗?
[assembly: ExportRenderer(typeof(CollectionView), typeof(CustomCollectionViewRenderer))]
namespace MyProj.Droid
{
public class CustomCollectionViewRenderer : CollectionViewRenderer
{
public CustomCollectionViewRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<ItemsView> elementChangedEvent)
{
base.OnElementChanged(elementChangedEvent);
if (elementChangedEvent.NewElement != null)
{
StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.Vertical);
SetLayoutManager(manager);
}
}
}
}
using Android.Content;
using Android.Support.V7.Widget;
using Test.Droid.PlatformRenderer;
using System.ComponentModel;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(CollectionView), typeof(CustomCollectionViewRenderer))]
namespace Test.Droid.PlatformRenderer
{
public class CustomCollectionViewRenderer : CollectionViewRenderer
{
public CustomCollectionViewRenderer(Context context) : base(context)
{
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs changedProperty)
{
base.OnElementPropertyChanged(sender, changedProperty);
}
protected override void OnElementChanged(ElementChangedEventArgs<ItemsView> elementChangedEvent)
{
base.OnElementChanged(elementChangedEvent);
if (elementChangedEvent.NewElement != null)
{
StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.Vertical);
SetLayoutManager(manager);
}
}
}
}
VS配置:Xamarin.Forms NuGet软件包版本为4.5.0.356
Visual Studio Professional 2019 for Mac版本8.3.4(内部版本8)
NuGet版本:5.3.0.6192
Xamarin.iOS版本:13.4.0.2
Xamarin.Android版本:10.0.3.0