【发布时间】:2016-02-02 14:20:04
【问题描述】:
我正在尝试自定义 Xamarin.Forms 选择器控件。在 android 和 ios 中,我将覆盖 Draw 事件并自己绘制控件。但是在 WinPhone 8.1 项目中,我无法覆盖 Draw 事件,因为它无法识别。下面是我在 android 和 ios 中使用的代码和 WinPhone 项目的屏幕截图,显示绘图事件不存在。
安卓
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 平台上参与此控件的绘制事件,我将不胜感激。
提前致谢。
【问题讨论】:
标签: c# mobile xamarin windows-phone-8.1 xamarin.forms