daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using Xamarin.Forms;
  3.  
  4. namespace MyApp.Controls
  5. {
  6.     public class CustomFrame : Frame
  7.     {
  8.         // ---------------------------------------------------------------------------------------------------------------
  9.         public static readonly BindableProperty CornerRadiusTopLeftProperty = BindableProperty.Create(
  10.             propertyName: "CornerRadiusTopLeft",
  11.             returnType: typeof(bool),
  12.             declaringType: typeof(CustomFrame),
  13.             defaultValue: true,
  14.             defaultBindingMode: BindingMode.TwoWay
  15.         );
  16.  
  17.         public bool CornerRadiusTopLeft
  18.         {
  19.             get { return (bool)GetValue(CornerRadiusTopLeftProperty); }
  20.             set { base.SetValue(CornerRadiusTopLeftProperty, value); }
  21.         }
  22.  
  23.         // ---------------------------------------------------------------------------------------------------------------
  24.         public static readonly BindableProperty CornerRadiusTopRightProperty = BindableProperty.Create(
  25.             propertyName: "CornerRadiusTopRight",
  26.             returnType: typeof(bool),
  27.             declaringType: typeof(CustomFrame),
  28.             defaultValue: true,
  29.             defaultBindingMode: BindingMode.TwoWay
  30.         );
  31.  
  32.         public bool CornerRadiusTopRight
  33.         {
  34.             get { return (bool)GetValue(CornerRadiusTopRightProperty); }
  35.             set { base.SetValue(CornerRadiusTopRightProperty, value); }
  36.         }
  37.  
  38.         // ---------------------------------------------------------------------------------------------------------------
  39.         public static readonly BindableProperty CornerRadiusBottomLeftProperty = BindableProperty.Create(
  40.             propertyName: "CornerRadiusBottomLeft",
  41.             returnType: typeof(bool),
  42.             declaringType: typeof(CustomFrame),
  43.             defaultValue: true,
  44.             defaultBindingMode: BindingMode.TwoWay
  45.         );
  46.  
  47.         public bool CornerRadiusBottomLeft
  48.         {
  49.             get { return (bool)GetValue(CornerRadiusBottomLeftProperty); }
  50.             set { base.SetValue(CornerRadiusBottomLeftProperty, value); }
  51.         }
  52.  
  53.         // ---------------------------------------------------------------------------------------------------------------
  54.         public static readonly BindableProperty CornerRadiusBottomRightProperty = BindableProperty.Create(
  55.             propertyName: "CornerRadiusBottomRight",
  56.             returnType: typeof(bool),
  57.             declaringType: typeof(CustomFrame),
  58.             defaultValue: true,
  59.             defaultBindingMode: BindingMode.TwoWay
  60.         );
  61.  
  62.         public bool CornerRadiusBottomRight
  63.         {
  64.             get { return (bool)GetValue(CornerRadiusBottomRightProperty); }
  65.             set { base.SetValue(CornerRadiusBottomRightProperty, value); }
  66.         }
  67.     }
  68. }
  69.    
  70. using System;
  71.  
  72. using CoreAnimation;
  73.  
  74. using MyApp.iOS.CustomRenderers;
  75. using Foundation;
  76. using MyApp.Controls;
  77. using UIKit;
  78. using Xamarin.Forms;
  79. using Xamarin.Forms.Platform.iOS;
  80.  
  81. [assembly: ExportRenderer(typeof(CustomFrame), typeof(CustomFrameRenderer))]
  82. namespace MyApp.iOS.CustomRenderers
  83. {
  84.     public class CustomFrameRenderer : FrameRenderer
  85.     {
  86.         protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
  87.         {
  88.             base.OnElementChanged(e);
  89.  
  90.             if (Element != null)
  91.             {
  92.                 var element = Element as CustomFrame;
  93.  
  94.                 int result = 0;
  95.  
  96.                 if (element.CornerRadiusTopLeft)
  97.                     result += (int)CACornerMask.MinXMinYCorner;
  98.  
  99.                 if (element.CornerRadiusTopRight)
  100.                     result += (int)CACornerMask.MaxXMinYCorner;
  101.  
  102.                 if (element.CornerRadiusBottomLeft)
  103.                     result += (int)CACornerMask.MinXMaxYCorner;
  104.  
  105.                 if (element.CornerRadiusBottomRight)
  106.                     result += (int)CACornerMask.MaxXMaxYCorner;
  107.  
  108.                 Layer.MaskedCorners = (CACornerMask)result;
  109.             };
  110.         }
  111.     }
  112. }
  113.    
  114. xmlns:customControls="clr-namespace:MyApp.Controls"
  115.    
  116. <customControls:CustomFrame BackgroundColor="White" CornerRadius="10" HasShadow="false"            
  117.         CornerRadiusBottomLeft="false" CornerRadiusBottomRight="false" VerticalOptions="Start" HorizontalOptions="FillAndExpand" Padding="15">
  118.  
  119.     <!-- Add your other elements here -->
  120. </customControls:CustomFrame>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top