Picker does not have the TextColor property that you mention.
Even so, we can still change the text color of Picker for WindowsPhone .
I assume you are inheriting from PickerRenderer since it was not in your sample code, and I added some additional things, so this is more useful for others: -
Define the interface in PCL : -
public interface ICustomPicker2 { Xamarin.Forms.Color MyBackgroundColor { get; set; } Xamarin.Forms.Color MyTextColor { get; set; } }
Xamarin.Forms Picker in PCL : -
public class CustomPicker2 : Xamarin.Forms.Picker , ICustomPicker2 { public static readonly BindableProperty MyBackgroundColorProperty = BindableProperty.Create<CustomPicker2, Xamarin.Forms.Color>(p => p.MyBackgroundColor, default(Xamarin.Forms.Color)); public static readonly BindableProperty MyTextColorProperty = BindableProperty.Create<CustomPicker2, Xamarin.Forms.Color>(p => p.MyTextColor, default(Xamarin.Forms.Color)); public Xamarin.Forms.Color MyTextColor { get { return (Xamarin.Forms.Color)GetValue(MyTextColorProperty); } set { SetValue(MyTextColorProperty, value); } } public Xamarin.Forms.Color MyBackgroundColor { get { return (Xamarin.Forms.Color)GetValue(MyBackgroundColorProperty); } set { SetValue(MyBackgroundColorProperty, value); } } }
Create a WindowsPhone renderer as in the class library: -
public class CustomPicker2Renderer : PickerRenderer { protected override void OnElementChanged(ElementChangedEventArgs<Picker> e) { base.OnElementChanged(e); var picker = e.NewElement; CustomPicker2 bp = (CustomPicker2)this.Element; if (this.Control != null) { var pickerStyle = new Style(typeof(Picker)) { Setters = { new Setter {Property = Picker.BackgroundColorProperty, Value = bp.MyBackgroundColor}, } }; SetPickerTextColor(bp.MyTextColor); picker.Style = pickerStyle; } } private void SetPickerTextColor(Xamarin.Forms.Color pobjColor) { byte bytR = (byte)(pobjColor.R * 255); byte bytG = (byte)(pobjColor.G * 255); byte bytB = (byte)(pobjColor.B * 255); byte bytA = (byte)(pobjColor.A * 255);
Please note that this is all you need if you just want to set the text color once.
However, if you want to change the color after its initial set, you will need to listen to the change in the property and act on it, as in the following: -
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e);
You will also need to export the renderer from the class library: -
[assembly: ExportRendererAttribute(typeof(CustomPicker2), typeof(CustomPicker2Renderer))]