Пример #1
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null || Element == null)
            {
                return;
            }

            if (e.NewElement is CustomGradientBackgroundButton button)
            {
                Button = button;

                Control.Touch += (object sender, TouchEventArgs args) =>
                {
                    switch (args.Event.Action)
                    {
                    case MotionEventActions.Down:
                        button.IsPressed = true;
                        Invalidate();
                        break;

                    case MotionEventActions.Up:
                        button.IsPressed = false;
                        Invalidate();
                        button.SendClicked();
                        break;
                    }
                };
            }
        }
Пример #2
0
        protected override void OnElementChanged(ElementChangedEventArgs <Button> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                return;
            }
            if (Equals(_button, null))
            {
                _button = e.NewElement as CustomGradientBackgroundButton;
            }

            Control.TouchDown += delegate
            {
                _button.IsPressed = true;
                SetNeedsDisplay();
            };
            Control.TouchUpInside += delegate
            {
                _button.IsPressed = false;
                SetNeedsDisplay();
            };
        }