I wanted to make a custom renderer for the Picker because it doesn't re-measure it's width according to the SelectedIndex and managed to do that with this (sneaky) renderer:
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using DigitalFleetTool.Droid.Renderers;
using System.ComponentModel;
[assembly: ExportRenderer(typeof(Picker), typeof(CustomPickerRenderer))]
namespace DigitalFleetTool.Droid.Renderers
{
public class CustomPickerRenderer : PickerRenderer
{
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName.Equals("SelectedIndex"))
{
var picker = (Picker)sender;
IVisualElementRenderer view = Platform.GetRenderer(picker);
view.ViewGroup.SetMinimumWidth(1);
}
}
}
}
However, I noticed it changed the layout of the Spinner
from the Xamarin default spinner to what seems to be the Android default spinner. I like the Xamarin one because it can display all options at once in my app which makes it easier to use, so I removed the override (so it basically contains no code) but it STILL changes the Spinner! The largest problem is that the spinner it changes to doesn't seem to be reachable through the Control
parameter and it's partly transparent (unusable) in my emulators. It seems to work on my real device, but I don't trust it to work on all devices after seeing it on the emulator.
http://imgur.com/a/bQJtA
http://imgur.com/a/Jqnly