Forum Xamarin.Forms

Is it feasible to add a background image to a picker control?

I am currently attempting to style a picker so that it "looks" like a dropdown element. In essence, all this has is a down arrow as a background image, positioned to the right end of the picker element. Just so it looks more familiar to the user as a selection element.

I am using a custom renderer anyway for my pickers, so (using ios as the example) I tried the following:

public class CustomPickerRenderer : PickerRenderer
{
// Override the OnElementChanged method so we can tweak this renderer post-initial setup
protected override void OnElementChanged(ElementChangedEventArgs e)
{
base.OnElementChanged(e);

        if (Control != null)
        {
            Control.TextColor = Color.Black.ToUIColor();
            Control.Background = UIImage.FromBundle("down.png");
        }
    }
}

I have tried every combination I can think of for the control.background value, and the image is sat in the resources directory for ios, with a build action of bundle resource. BackgroundColor works perfectly, so I am surprised that this does not. I am testing on a simulator for IOS9 - so I am hoping that THAT is not the issue!

I may be going about this in the wrong way, it may/may not be feasible, or it could be something simple. Either way, I have been trying to find an example of this for hours and no joy - so thought I would ask here.

Any help is appreciated.

Sign In or Register to comment.