0
我想自定義Xamarin.Forms選取器控件。在android和ios中,我重寫Draw事件並自己繪製控件。但是,在WinPhone 8.1項目中,我無法重寫Draw事件,因爲它不被識別。下面是我在android和ios中使用的代碼以及WinPhone項目的屏幕截圖,顯示繪製事件不存在。自定義拾取器渲染器繪製事件無法識別Xamarin.Forms 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平臺上的這個控件的繪製事件有任何想法,我會非常感激。
在此先感謝。