Reputation: 975
I am trying to customize Xamarin.Forms picker control. In android and ios I am overriding the Draw event and drawing the control myself. However on the WinPhone 8.1 project I am unable to override the Draw event because it is not recognized. Below is the code I am using in android and ios and a screen capture of the WinPhone project showing that the draw event doesnt exist.
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
If anyone has any idea on how I can get into the draw event of this control on the Windows Phone 8.1 platform I'd greatly appreciate it.
Thanks in advance.
Upvotes: 0
Views: 1283
Reputation: 4746
WindowsPhone
does not have direct drawing abilities.
You will want to create a control hierarchy of some sort to get around your needs for the Windows Phone
platform.
If you want to do custom drawing, use something like a WriteableBitmap
and render into an image control for example.
Alternatively maybe look at NGraphics, with a wrapper control for it for Xamarin.Forms
here.
Upvotes: 2