コード例 #1
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null && _drawableEnabled)
            {
                _drawableEnabled = false;
                _backgroundDrawable.Reset();
                _backgroundDrawable = null;
            }
            UpdateDrawable();
        }
コード例 #2
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_backgroundDrawable != null)
                {
                    _backgroundDrawable.Dispose();
                    _backgroundDrawable = null;
                }
            }

            base.Dispose(disposing);
        }
コード例 #3
0
        private void UpdateDrawable()
        {
            if (Element.BackgroundColor == Color.Default)
            {
                if (!_drawableEnabled)
                {
                    return;
                }

                if (_defaultDrawable != null)
                {
                    Control.SetBackground(_defaultDrawable);
                }

                _drawableEnabled = false;
            }
            else
            {
                if (_backgroundDrawable == null)
                {
                    _backgroundDrawable = new ButtonDrawable();
                }

                _backgroundDrawable.Button = Element;

                if (_drawableEnabled)
                {
                    return;
                }

                if (_defaultDrawable == null)
                {
                    _defaultDrawable = Control.Background;
                }

                Control.SetBackground(_backgroundDrawable.GetDrawable());
                _drawableEnabled = true;
            }

            Control.Invalidate();
        }