Hello @Michal ,
Welcome to our Microsoft Q&A platform!
Xamarin.Forms.Entry doesn't provide the 'BorderColor' property directly. To change the entry's border color, try to perform the work on the native platform. You could use Custom Renderer for this function.
Here is the sample code, you could refer to it.
Android Platform
[assembly:ExportRenderer(typeof(StandardEntry),typeof(CustomEntryRenderer))]
namespace TestApplication_6.Droid
{
public class CustomEntryRenderer : EntryRenderer
{
StandardEntry entry;
public CustomEntryRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
entry = Element as StandardEntry;
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
var nativeEditText = (EditText)Control;
var shape = new ShapeDrawable(new Android.Graphics.Drawables.Shapes.RectShape());
shape.Paint.Color = entry.BorderColor.ToAndroid(); //entry.BorderColor is the 'BorderColor' property of the custom entry class
shape.Paint.SetStyle(Paint.Style.Stroke);
shape.Paint.StrokeWidth = 10;
nativeEditText.Background = shape;
}
}
}
iOS platform
[assembly: ExportRenderer(typeof(StandardEntry), typeof(CustomEntryRenderer))]
namespace TestApplication_6.iOS
{
public class CustomEntryRenderer : EntryRenderer
{
StandardEntry entry;
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
entry = Element as StandardEntry;
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
Control.Layer.BorderColor = entry.BorderColor.ToCGColor();
Control.Layer.BorderWidth = 2;
}
}
}
Then you could change the value of customized 'BorderColor' property to change the color of the entry in .cs file.
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.