protected override void OnElementChanged(ElementChangedEventArgs <Controls.Button> e) { base.OnElementChanged(e); if (e.OldElement == null) { AButton button = Control; if (button == null) { button = CreateNativeControl(); button.SetOnClickListener(ButtonClickListener.Instance.Value); button.SetOnTouchListener(ButtonTouchListener.Instance.Value); button.Tag = this; SetNativeControl(button); button.Focusable = false; button.FocusableInTouchMode = false; _textColorSwitcher = new TextColorSwitcher(button.TextColors); button.AddOnAttachStateChangeListener(this); } } else { if (_drawableEnabled) { _drawableEnabled = false; _backgroundDrawable.Reset(); _backgroundDrawable = null; } } UpdateAll(); }
protected override void Dispose(bool disposing) { if (_isDisposed) { return; } _isDisposed = true; if (disposing) { if (_backgroundDrawable != null) { _backgroundDrawable.Dispose(); _backgroundDrawable = null; } } base.Dispose(disposing); }
void UpdateDrawable() { if (Element.BackgroundColor == Xamarin.Forms.Color.Default) { if (!_drawableEnabled) { return; } if (_defaultDrawable != null) { Control.SetBackground(_defaultDrawable); } _drawableEnabled = false; } else { if (_backgroundDrawable == null) { _backgroundDrawable = new ButtonDrawable(Context.ToPixels); } _backgroundDrawable.Button = Element; if (_drawableEnabled) { return; } if (_defaultDrawable == null) { _defaultDrawable = Control.Background; } Control.SetBackground(_backgroundDrawable); _drawableEnabled = true; } Control.Invalidate(); }