How to change input border color in Xamarin.Forms

I am writing an application on the Xamarin.forms platform. There are several entries in the application, and I want to create / change the border color to red. Is there an easy way to do this? or is there any way?

+4
source share
1 answer

I think you can only achieve this with CustomRenderer:

IOS:

protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
       base.OnElementPropertyChanged(sender, e);

       Control.Layer.BorderColor = UIColor.Red.CGColor;
       Control.Layer.BorderWidth = 1;
}

On Android, I think this is possible without CustomRender (in fact, if it is ... I don't know how ~ Sorry):

Using CustomRenderer would be something like this:

    [assembly: ExportRenderer(typeof(Entry), typeof(SuperEntryRenderer))]
    namespace Bla{
    public class SuperEntryRenderer : EntryRenderer
        {
            protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
            {
                base.OnElementChanged(e);
                if (e.OldElement == null)
                {
                    var nativeEditText = (global::Android.Widget.EditText)Control;
                    var shape = new ShapeDrawable(new Android.Graphics.Drawables.Shapes.RectShape());
                    shape.Paint.Color = Xamarin.Forms.Color.Red.ToAndroid();
                    shape.Paint.SetStyle(Paint.Style.Stroke);
                    nativeEditText.Background = shape;
                }
            }
        }
+11
source

All Articles