Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Xamarin.Forms;
- namespace MyApp.Controls
- {
- public class CustomFrame : Frame
- {
- // ---------------------------------------------------------------------------------------------------------------
- public static readonly BindableProperty CornerRadiusTopLeftProperty = BindableProperty.Create(
- propertyName: "CornerRadiusTopLeft",
- returnType: typeof(bool),
- declaringType: typeof(CustomFrame),
- defaultValue: true,
- defaultBindingMode: BindingMode.TwoWay
- );
- public bool CornerRadiusTopLeft
- {
- get { return (bool)GetValue(CornerRadiusTopLeftProperty); }
- set { base.SetValue(CornerRadiusTopLeftProperty, value); }
- }
- // ---------------------------------------------------------------------------------------------------------------
- public static readonly BindableProperty CornerRadiusTopRightProperty = BindableProperty.Create(
- propertyName: "CornerRadiusTopRight",
- returnType: typeof(bool),
- declaringType: typeof(CustomFrame),
- defaultValue: true,
- defaultBindingMode: BindingMode.TwoWay
- );
- public bool CornerRadiusTopRight
- {
- get { return (bool)GetValue(CornerRadiusTopRightProperty); }
- set { base.SetValue(CornerRadiusTopRightProperty, value); }
- }
- // ---------------------------------------------------------------------------------------------------------------
- public static readonly BindableProperty CornerRadiusBottomLeftProperty = BindableProperty.Create(
- propertyName: "CornerRadiusBottomLeft",
- returnType: typeof(bool),
- declaringType: typeof(CustomFrame),
- defaultValue: true,
- defaultBindingMode: BindingMode.TwoWay
- );
- public bool CornerRadiusBottomLeft
- {
- get { return (bool)GetValue(CornerRadiusBottomLeftProperty); }
- set { base.SetValue(CornerRadiusBottomLeftProperty, value); }
- }
- // ---------------------------------------------------------------------------------------------------------------
- public static readonly BindableProperty CornerRadiusBottomRightProperty = BindableProperty.Create(
- propertyName: "CornerRadiusBottomRight",
- returnType: typeof(bool),
- declaringType: typeof(CustomFrame),
- defaultValue: true,
- defaultBindingMode: BindingMode.TwoWay
- );
- public bool CornerRadiusBottomRight
- {
- get { return (bool)GetValue(CornerRadiusBottomRightProperty); }
- set { base.SetValue(CornerRadiusBottomRightProperty, value); }
- }
- }
- }
- using System;
- using CoreAnimation;
- using MyApp.iOS.CustomRenderers;
- using Foundation;
- using MyApp.Controls;
- using UIKit;
- using Xamarin.Forms;
- using Xamarin.Forms.Platform.iOS;
- [assembly: ExportRenderer(typeof(CustomFrame), typeof(CustomFrameRenderer))]
- namespace MyApp.iOS.CustomRenderers
- {
- public class CustomFrameRenderer : FrameRenderer
- {
- protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
- {
- base.OnElementChanged(e);
- if (Element != null)
- {
- var element = Element as CustomFrame;
- int result = 0;
- if (element.CornerRadiusTopLeft)
- result += (int)CACornerMask.MinXMinYCorner;
- if (element.CornerRadiusTopRight)
- result += (int)CACornerMask.MaxXMinYCorner;
- if (element.CornerRadiusBottomLeft)
- result += (int)CACornerMask.MinXMaxYCorner;
- if (element.CornerRadiusBottomRight)
- result += (int)CACornerMask.MaxXMaxYCorner;
- Layer.MaskedCorners = (CACornerMask)result;
- };
- }
- }
- }
- xmlns:customControls="clr-namespace:MyApp.Controls"
- <customControls:CustomFrame BackgroundColor="White" CornerRadius="10" HasShadow="false"
- CornerRadiusBottomLeft="false" CornerRadiusBottomRight="false" VerticalOptions="Start" HorizontalOptions="FillAndExpand" Padding="15">
- <!-- Add your other elements here -->
- </customControls:CustomFrame>
Add Comment
Please, Sign In to add comment