我正在尝试自定义Xamarin.Forms选择器控件。在android和ios中,我重写Draw事件并自己绘制控件。但是在WinPhone 8.1项目中,我无法覆盖Draw事件,因为它无法识别。下面是我在android和ios中使用的代码以及WinPhone项目的屏幕截图,显示绘制事件不存在。
的Android
using Android.Graphics;
using Namespace.CustomControls;
using Namespace.Droid.Renderers;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRendererAttribute(typeof(BindablePicker), typeof(BindablePickerRenderer))]
namespace Namespace.Droid.Renderers
{
public class BindablePickerRenderer : PickerRenderer
{
public BindablePickerRenderer()
{
this.SetWillNotDraw(false);
}
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged(e);
this.Element.PropertyChanged += (s_, e_) => Invalidate();
}
public override void Draw(Canvas canvas)
{
BindablePicker bp = (BindablePicker)this.Element;
// Code to draw my control
}
}
}
IOS
using System;
using System.Collections.Generic;
using System.Text;
using CoreGraphics;
using Xamarin.Forms.Platform.iOS;
using Namespace.CustomControls;
using UIKit;
using Xamarin.Forms;
using Namespace.iOS.Renderers;
[assembly: ExportRendererAttribute(typeof(BindablePicker), typeof(BindablePickerRenderer))]
namespace Namespace.iOS.Renderers
{
public class BindablePickerRenderer : PickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged(e);
this.Element.PropertyChanged += (s_, e_) => SetNeedsDisplay();
}
public override void Draw(CGRect rect)
{
BindablePicker bp = (BindablePicker)this.Element;
// Code to draw my control
}
}
}
WinPhone
如果有人知道如何在Windows Phone 8.1平台上进入此控件的绘制事件,我将非常感激。
提前致谢。