protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            // get a copy of the xamarin control we are changing
            SelectImageButton formControl = (SelectImageButton)sender;

            // get the selected state and hold colors and widths and set them to be used thoughout the renderer
            droidBackgroundColor = formControl.BackgroundColor.ToAndroid();
            droidBorderColor     = formControl.BorderColor.ToAndroid();
            droidBorderWidth     = formControl.BorderWidth * 2;

            droidHoldBackgroundColor = formControl.HoldBackgroundColor.ToAndroid();
            droidHoldBorderColor     = formControl.HoldBorderColor.ToAndroid();
            droidHoldBorderWidth     = formControl.HoldBorderWidth * 2;

            base.OnElementPropertyChanged(formControl, e);

            // test of setting the padding for this before drawing a background
            this.SetClipChildren(true);

            // create a drawable color and set irs raduis, color, and border
            var rad = new global::Android.Graphics.Drawables.GradientDrawable();

            rad.SetCornerRadius(1000.00F);
            rad.SetColor(droidBackgroundColor);
            rad.SetStroke(droidBorderWidth, droidBorderColor);
            // apply the drawable to the background
            this.Background = rad;

            // set the draw border
            drawBorderWidth = (float)formControl.BorderWidth * 2;
        }
        // this will draw background and circular border then it will cut the image to a circle inside the border and padding
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
            // the control as it exists in the protable project
            formControl = (SelectImageButton)sender;
            // the click events form the forms control to be added to the end of the long click
            buttonevents = formControl.ClickEvents;
            // setting the colors for use in ther renderer outside of the property changed event
            iosBackgroundColor     = formControl.BackgroundColor.ToCGColor();
            iosBorderColor         = formControl.BorderColor.ToCGColor();
            iosBorderWidth         = formControl.BorderWidth;
            iosHoldBackgroundColor = formControl.HoldBackgroundColor.ToCGColor();
            iosHoldBorderColor     = formControl.HoldBorderColor.ToCGColor();
            iosHoldBorderWidth     = formControl.HoldBorderWidth;
            // background
            Xamarin.Forms.Color bgcolor = formControl.BackgroundColor;
            Layer.BackgroundColor = bgcolor.ToCGColor();
            // border
            Layer.BorderColor = formControl.BorderColor.ToCGColor();
            Layer.BorderWidth = formControl.BorderWidth;

            Layer.CornerRadius = (float)formControl.Width / 2;
            // setup for a long press gesture
            UILongPressGestureRecognizer holdGesture = new UILongPressGestureRecognizer(holdPress);

            holdGesture.MinimumPressDuration = 0.0;
            this.AddGestureRecognizer(holdGesture);
            // this need to check that the control is actually loaded as it can call this method without the control present
            if (formControl != null)
            {
                // a top left and bottom right adjustment for the clipping border
                float TLborderControl = 0;
                float BRborderControl = formControl.BorderWidth;

                // a rectangle made usiing the bounds and borders of the control that we will use the cut an elipse with
                CGRect clipRect = new CGRect();

                clipRect.X      = (float)0 + TLborderControl;
                clipRect.Y      = (float)0 + TLborderControl;
                clipRect.Width  = (float)Element.Bounds.Width;
                clipRect.Height = (float)Element.Bounds.Height;

                CAShapeLayer clipShapeLayer = new CAShapeLayer();
                CGPath       clipPath       = new CGPath();

                clipPath.AddEllipseInRect(clipRect);
                clipShapeLayer.Path = clipPath;
                Layer.Mask          = clipShapeLayer;
            }
        }
Exemplo n.º 3
0
 private void CropButton_Click(object sender, EventArgs e)
 {
     if (PictureBox1.Image == null)
     {
         alert.Show();
     }
     else
     {
         if (boolcrop == true)
         {
             SelectImageButton.Show();
             CropImageButton.Show();
             boolcrop = false;
         }
         else if (boolcrop == false)
         {
             SelectImageButton.Hide();
             CropImageButton.Hide();
             boolcrop = true;
         }
     }
 }