Esempio n. 1
0
        protected override void OnElementChanged(ElementChangedEventArgs <GradientTextButton> e)
        {
            //base.OnElementChanged(e);
            if (e.NewElement != null)
            {
                button = e.NewElement;
            }
            var linear = BackgroundExtension.CreateGradientBrush(button.StartColor.ToWindows(),
                                                                 button.EndColor.ToWindows(),
                                                                 button.CenterColor.ToWindows(),
                                                                 button.Angle.ToWindows());

            nButton = new Button
            {
                Content         = button.Text,
                Background      = new SolidColorBrush(button.BackgroundColor.ToWindows()),
                Foreground      = linear,
                BorderBrush     = linear,
                BorderThickness = new Thickness(button.BorderWidth),
                Style           = Application.Current.Resources["ButtonRevealStyle"] as Style
            };
            nButton.Click   += (s, ev) => { button.SendClicked(); };
            nButton.Holding += (s, ev) => { button.SendLongClick(); };
            SetNativeControl(nButton);
        }
 private void NButton_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
 {
     nButton.Background = BackgroundExtension.CreateGradientBrush(button.StartColor.ToWindows(),
                                                                  button.EndColor.ToWindows(),
                                                                  button.CenterColor.ToWindows(),
                                                                  button.Angle.ToWindows());
 }
        private Drawable CreateBackgroundButton()
        {
            var layer1 = BackgroundExtension.CreateBackgroundGradient(button.StartColor.ToAndroid(),
                                                                      button.EndColor.ToAndroid(),
                                                                      button.CenterColor.ToAndroid(), button.CornerRadius, button.Angle.ToAndroid());
            var layer1Disabled = BackgroundExtension.CreateBackgroundGradient(Android.Graphics.Color.Gray,
                                                                              Android.Graphics.Color.Gray,
                                                                              Android.Graphics.Color.Gray, button.CornerRadius, button.Angle.ToAndroid());
            var layer2Temp = BackgroundExtension.CreateBackgroundGradient(backgroundColor.ToAndroid(),
                                                                          backgroundColor.ToAndroid(),
                                                                          backgroundColor.ToAndroid(), button.CornerRadius, button.Angle.ToAndroid());
            int borderWidth = (int)button.BorderWidth;
            var layer2      = new InsetDrawable(layer2Temp, borderWidth, borderWidth, borderWidth, borderWidth);

            Drawable[]    drawables          = new Drawable[] { layer1, layer2 };
            Drawable[]    drawablesDisabled  = new Drawable[] { layer1Disabled, layer2 };
            LayerDrawable layer              = new LayerDrawable(drawables);
            LayerDrawable layerDisabled      = new LayerDrawable(drawablesDisabled);
            var           statesListDrawable = new StateListDrawable();

            statesListDrawable.AddState(new int[] { -Android.Resource.Attribute.StateEnabled }, layerDisabled);
            statesListDrawable.AddState(new int[] { Android.Resource.Attribute.StatePressed }, layer);
            statesListDrawable.AddState(new int[] { Android.Resource.Attribute.StateEnabled }, layer);
            return(statesListDrawable);
        }
 Brush CreateBackgroundUnToggle()
 {
     return(BackgroundExtension.CreateGradientBrush(button.StartColor.ToWindows(),
                                                    button.EndColor.ToWindows(),
                                                    button.CenterColor.ToWindows(),
                                                    button.Angle.ToWindows()));
 }
Esempio n. 5
0
 private void Border_Loaded(object sender, RoutedEventArgs e)
 {
     border.Background = BackgroundExtension.CreateGradientBrush(frame.StartColor.ToWindows(),
                                                                 frame.EndColor.ToWindows(),
                                                                 frame.CenterColor.ToWindows(),
                                                                 frame.Angle.ToWindows());
     border.CornerRadius = frame.CornerRadius > 0 ? new CornerRadius(frame.CornerRadius) : new CornerRadius(0);
 }
 void CreateUnToggleBackground()
 {
     nButton.BackgroundColor   = UIColor.Clear;
     nButton.Layer.BorderColor = UIColor.Clear.CGColor;
     nButton.Layer.BorderWidth = 0;
     nButton.Layer.Sublayers   = null;
     nButton.Layer.InsertSublayer(BackgroundExtension.CreateBackgroundGradientLayer((float)button.Height, (float)button.Width, button.CornerRadius, button.StartColor.ToUIColor(),
                                                                                    button.EndColor.ToUIColor(), button.CenterColor.ToUIColor(), button.Angle.ToiOS()), 0);
 }
 private void NButton_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
 {
     nButton.Background = BackgroundExtension.CreateGradientBrush(button.StartColor.ToWindows(),
                                                                  button.EndColor.ToWindows(),
                                                                  button.CenterColor.ToWindows(),
                                                                  button.Angle.ToWindows());
     if (button.Image != null && !string.IsNullOrEmpty(button.Image.File))
     {
         RenderImage();
     }
 }
        private Drawable CreateBackground()
        {
            var normalDrawable     = BackgroundExtension.CreateBackgroundColor(entry.BackgroundColor.ToAndroid(), (float)entry.CornerRadius);
            var focusDrawable      = BackgroundExtension.CreateBackgroundColor(entry.FocusColor.ToAndroid(), (float)entry.CornerRadius);
            var disabledDrawable   = BackgroundExtension.CreateBackgroundColor(entry.DisabledColor.ToAndroid(), (float)entry.CornerRadius);
            var statesListDrawable = new StateListDrawable();

            statesListDrawable.AddState(new int[] { Android.Resource.Attribute.StateFocused }, focusDrawable);
            statesListDrawable.AddState(new int[] { -Android.Resource.Attribute.StateEnabled }, disabledDrawable);
            statesListDrawable.AddState(new int[] { -Android.Resource.Attribute.StateFirst }, normalDrawable);
            return(new InsetDrawable(statesListDrawable, 0, 4, 0, 0));
        }
 private Shader CreateGradient()
 {
     if (button.IsEnabled)
     {
         return(BackgroundExtension.CreateLinearGradient(button.StartColor.ToAndroid(),
                                                         button.EndColor.ToAndroid(),
                                                         button.CenterColor.ToAndroid(), (float)button.Width, (float)button.Height));
     }
     return(BackgroundExtension.CreateLinearGradient(Android.Graphics.Color.Gray,
                                                     Android.Graphics.Color.Gray,
                                                     Android.Graphics.Color.Gray, (float)button.Width, (float)button.Height));
 }
 void CreateToggleBackground()
 {
     nButton.BackgroundColor   = UIColor.Clear;
     nButton.Layer.BorderColor = UIColor.Clear.CGColor;
     nButton.Layer.BorderWidth = 0;
     nButton.Layer.Sublayers   = null;
     nButton.Layer.InsertSublayer(BackgroundExtension.CreateBackgroundGradientLayer((float)button.Height, (float)button.Width, button.CornerRadius, button.ToggleStartColor.ToUIColor(),
                                                                                    button.ToggleEndColor.ToUIColor(), button.ToggleCenterColor.ToUIColor(), button.Angle.ToiOS()), 0);
     if (button.Image != null && button.Image.File.Length > 0)
     {
         var background = BackgroundExtension.CreateBackgroundImage((float)button.Height, (float)button.Width, button.CornerRadius, button.Image.File);
         nButton.Layer.InsertSublayer(background, 1);
     }
 }
Esempio n. 11
0
 protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     base.OnElementPropertyChanged(sender, e);
     if (e.PropertyName == "Width" || e.PropertyName == "Height")
     {
         Layer.BackgroundColor = UIColor.Clear.CGColor;
         Layer.BorderColor     = UIColor.Clear.CGColor;
         Layer.BorderWidth     = 0;
         Layer.InsertSublayer(BackgroundExtension.CreateBackgroundGradientLayer((float)frame.Height, (float)frame.Width, frame.CornerRadius, frame.StartColor.ToUIColor(),
                                                                                frame.EndColor.ToUIColor(), frame.CenterColor.ToUIColor(), frame.Angle.ToiOS()), 0);
         if (frame.Image != null && frame.Image.File.Length > 0)
         {
             var background = BackgroundExtension.CreateBackgroundImage((float)frame.Height, (float)frame.Width, frame.CornerRadius, frame.Image.File);
             Layer.InsertSublayer(background, 0);
         }
     }
 }
Esempio n. 12
0
 protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     base.OnElementPropertyChanged(sender, e);
     if (e.PropertyName == nameof(button.Width) || e.PropertyName == nameof(button.Height))
     {
         nButton.BackgroundColor   = UIColor.Clear;
         nButton.Layer.BorderColor = UIColor.Clear.CGColor;
         nButton.Layer.BorderWidth = 0;
         nButton.Layer.InsertSublayer(BackgroundExtension.CreateBackgroundGradientLayer((float)button.Height, (float)button.Width, button.CornerRadius, button.StartColor.ToUIColor(),
                                                                                        button.EndColor.ToUIColor(), button.CenterColor.ToUIColor(), button.Angle.ToiOS()), 0);
         if (button.Image != null && button.Image.File.Length > 0)
         {
             var background = BackgroundExtension.CreateBackgroundImage((float)button.Height, (float)button.Width, button.CornerRadius, button.Image.File);
             nButton.Layer.InsertSublayer(background, 1);
         }
     }
 }
Esempio n. 13
0
        private Drawable CreateBackgroundFrame()
        {
            List <Drawable> drawables = new List <Drawable>();
            var             layer1    = BackgroundExtension.CreateBackgroundGradient(grid.StartColor.ToAndroid(),
                                                                                     grid.EndColor.ToAndroid(),
                                                                                     grid.CenterColor.ToAndroid(), grid.CornerRadius, grid.Angle.ToAndroid());

            drawables.Add(layer1);
            if (grid.Image != null && !string.IsNullOrEmpty(grid.Image.File))
            {
                var bitmapDrawable = BackgroundExtension.CreateBackgroundBitmap(grid.Image.File, (int)grid.Height,
                                                                                (int)grid.Width, grid.CornerRadius);
                if (bitmapDrawable != null)
                {
                    drawables.Add(bitmapDrawable);
                }
            }
            return(new LayerDrawable(drawables.ToArray()));
        }
Esempio n. 14
0
        Drawable CreateBackgroundForButton(bool renderImage = true)
        {
            List <Drawable> drawables         = new List <Drawable>();
            List <Drawable> drawablesDisabled = new List <Drawable>();

            drawables.Add(BackgroundExtension.CreateBackgroundGradient(button.StartColor.ToAndroid(),
                                                                       button.EndColor.ToAndroid(),
                                                                       button.CenterColor.ToAndroid(),
                                                                       button.CornerRadius,
                                                                       button.Angle.ToAndroid()));
            drawablesDisabled.Add(BackgroundExtension.CreateBackgroundGradient(button.StartColor.ToAndroid(),
                                                                               button.EndColor.ToAndroid(),
                                                                               button.CenterColor.ToAndroid(),
                                                                               button.CornerRadius,
                                                                               button.Angle.ToAndroid()));
            if (button.Image != null && !string.IsNullOrEmpty(button.Image.File) && renderImage)
            {
                var bitmapDrawable = BackgroundExtension.CreateBackgroundBitmap(button.Image.File, (int)button.HeightRequest,
                                                                                (int)button.WidthRequest, button.CornerRadius);
                if (bitmapDrawable != null)
                {
                    drawables.Add(bitmapDrawable);
                    drawablesDisabled.Add(bitmapDrawable);
                }
            }
            Drawable layer         = new LayerDrawable(drawables.ToArray());
            Drawable layerDisabled = new LayerDrawable(drawablesDisabled.ToArray());

            layerDisabled.Mutate().Alpha = 80;
            var statesListDrawable       = new StateListDrawable();

            statesListDrawable.AddState(new int[] { -Android.Resource.Attribute.StateEnabled }, layerDisabled);
            statesListDrawable.AddState(new int[] { Android.Resource.Attribute.StatePressed }, layer);
            statesListDrawable.AddState(new int[] { Android.Resource.Attribute.StateEnabled }, layer);
            return(statesListDrawable);
        }