{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
- AccessibilityHighlightable = false,
+ AccessibilityHighlightable = false
};
}
buttonText = CreateText();
buttonIcon = CreateIcon();
- buttonText.Relayout += OnTextRelayout;
- buttonIcon.Relayout += OnIconRelayout;
LayoutItems();
#if PROFILE_MOBILE
}
}
- private void OnTextOrIconUpdated()
- {
- if (buttonIcon == null || buttonText == null)
- {
- return;
- }
-
- float lengthWithoutText = 0;
-
- if (iconPadding == null || buttonIcon.Size.Width == 0 || buttonIcon.Size.Height == 0)
- {
- buttonIcon.Margin = new Extents(0);
- lengthWithoutText = buttonIcon.Size.Width;
- }
- else if (iconRelativeOrientation == IconOrientation.Left || iconRelativeOrientation == IconOrientation.Right)
- {
- buttonIcon.Margin = new Extents(iconPadding.Start, iconPadding.End, 0, 0);
- lengthWithoutText = iconPadding.Start + iconPadding.End + buttonIcon.Size.Width;
- }
- else
- {
- buttonIcon.Margin = new Extents(0, 0, iconPadding.Top, iconPadding.Bottom);
- }
-
- if (textPadding == null || buttonText.Size.Width == 0 || buttonText.Size.Height == 0)
- {
- buttonText.Margin = new Extents(0);
- }
- else
- {
- if (iconRelativeOrientation == IconOrientation.Left || iconRelativeOrientation == IconOrientation.Right)
- {
- buttonText.Margin = new Extents(textPadding.Start, textPadding.End, 0, 0);
- lengthWithoutText += textPadding.Start + textPadding.End;
- }
- else
- {
- buttonText.Margin = new Extents(0, 0, textPadding.Top, textPadding.Bottom);
- }
- }
-
- // If the button has fixed width and the text is not empty, the text should not exceed button boundary.
- if (WidthSpecification >= 0 && !String.IsNullOrEmpty(buttonText.Text))
- {
- buttonText.MaximumSize = new Size2D(Math.Max(WidthSpecification - (int)lengthWithoutText, Math.Max((int)buttonText.MinimumSize.Width, 1)), HeightSpecification);
- }
- }
-
- private void OnIconRelayout(object sender, EventArgs args)
- {
- OnTextOrIconUpdated();
- }
-
- private void OnTextRelayout(object sender, EventArgs args)
- {
- OnTextOrIconUpdated();
- }
-
private void OnClickedInternal(ClickedEventArgs eventArgs)
{
Command?.Execute(CommandParameter);
{
var instance = (Button)bindable;
instance.iconPadding = (Extents)((Extents)newValue).Clone();
- instance.OnTextOrIconUpdated();
+ if (instance.buttonIcon != null)
+ {
+ instance.buttonIcon.Margin = instance.iconPadding;
+ }
},
defaultValueCreator: (bindable) => ((Button)bindable).iconPadding);
{
var instance = (Button)bindable;
instance.textPadding = (Extents)((Extents)newValue).Clone();
- instance.OnTextOrIconUpdated();
+ if (instance.buttonText != null)
+ {
+ instance.buttonText.Margin = instance.textPadding;
+ }
},
defaultValueCreator: (bindable) => ((Button)bindable).textPadding);
if (Extension != null)
{
buttonIcon.Unparent();
- buttonIcon.Relayout -= OnIconRelayout;
- buttonIcon = Extension.OnCreateIcon(this, buttonIcon);
- buttonIcon.Relayout += OnIconRelayout;
-
buttonText.Unparent();
- buttonText.Relayout -= OnTextRelayout;
+ buttonIcon = Extension.OnCreateIcon(this, buttonIcon);
buttonText = Extension.OnCreateText(this, buttonText);
- buttonText.Relayout += OnTextRelayout;
-
LayoutItems();
}