Border Color for Editor in Xamarin.Forms

前端 未结 8 973
[愿得一人]
[愿得一人] 2020-12-29 05:06

How can i make a border color for Editor in Xamarin.Forms?

I used this link, but it works only for Android. I want it to work in all platforms!

I\'m a little

8条回答
  •  太阳男子
    2020-12-29 05:51

    Here's the complete solution I used. You need three things.

    1 - A custom class that implements Editor in your forms project.

    public class BorderedEditor : Editor
    {
    
    }
    

    2 - A custom renderer for your custom Editor in your iOS project.

    public class BorderedEditorRenderer : EditorRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs e)
        {
            base.OnElementChanged(e);
    
            if (Control != null)
            {
                Control.Layer.CornerRadius = 3;
                Control.Layer.BorderColor = Color.FromHex("F0F0F0").ToCGColor();
                Control.Layer.BorderWidth = 2;
            }
        }
    }
    

    3 - An ExportRenderer attribute in your iOS project that tells Xamarin to use your custom renderer for your custom editor.

    [assembly: ExportRenderer(typeof(BorderedEditor), typeof(BorderedEditorRenderer))]
    

    Then use your custom editor in Xaml:

    
    

提交回复
热议问题