Corner border for Frame

In Xamarin Forms by setting CornerRadius='some value' will render the frame accordingly in iOS and Android.
But in UWP frame is rendered as a sharp / rectangle border.

Fix for this:
In UWP native project we have to write a renderer class for FrameRenderer as below.

public class FrameRenderer : Xamarin.Forms.Platform.UWP.FrameRenderer
{           
        protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                var frame = e.NewElement;
                Windows.UI.Color frameBG = Windows.UI.Color.FromArgb(
                    (byte)(frame.BackgroundColor.A * 255),
                    (byte)(frame.BackgroundColor.R * 255),
                    (byte)(frame.BackgroundColor.G * 255),
                    (byte)(frame.BackgroundColor.B * 255));

                if (frame.CornerRadius > -1)
                {
                    Control.CornerRadius = new Windows.UI.Xaml.CornerRadius(frame.CornerRadius);
                    Control.Background = new SolidColorBrush(frameBG);
                    frame.BackgroundColor = Xamarin.Forms.Color.Transparent;
                }
            }
        }
    }

Posts

Sign In or Register to comment.