static void UpdateButtonFields(System.Windows.Controls.Button button, bool enabled, string text, IObserver <Points> width) { button.Content = text; button.IsEnabled = enabled; button.Measure(new System.Windows.Size(double.MaxValue, double.MaxValue)); width.OnNext(button.DesiredSize.Width); }
/// <summary> /// Gets the Size element associated with a Button. /// </summary> /// <param name="button">The Button element to Measure.</param> /// <returns>The Button Size.</returns> private static Size GetArrowButtonSize(Button button) { button.Visibility = Visibility.Visible; Size size = new Size(button.ActualWidth, button.ActualHeight); if (0 == size.Width || 0 == size.Height) { button.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); } if (0 == size.Width) { size.Width = button.DesiredSize.Width; } if (0 == size.Height) { size.Height = button.DesiredSize.Height; } button.Visibility = Visibility.Collapsed; return size; }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } var valueType = value.GetType(); if (valueType == typeof(Button)) { var button = (Button)value; return new MessageButton {Button = button}; } if (valueType == typeof(string)) { var textFragments = value.ToString().Split(';'); var button = new Button {Content = textFragments[0]}; var mbutton = new MessageButton {Button = button}; button.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); button.Width = Math.Max(80, button.DesiredSize.Width); button.Height = Math.Max(22, button.DesiredSize.Height); if (textFragments.Length > 1) { var rightToLeftIndex = 0; if (int.TryParse(textFragments[1], out rightToLeftIndex)) { mbutton.RightToLeftIndex = rightToLeftIndex; } } if (textFragments.Length > 2) { var resultFragment = textFragments[2].ToUpper(); if (string.Equals(resultFragment, "OK")) { mbutton.Result = MessageResult.OK; } else if (string.Equals(resultFragment, "CANCEL")) { mbutton.Result = MessageResult.Cancel; } else if (string.Equals(resultFragment, "OTHER")) { mbutton.Result = MessageResult.Other; } else if (string.Equals(resultFragment, "NULL")) { mbutton.Result = null; } else if (!string.Equals(resultFragment, string.Empty)) { mbutton.Result = textFragments[2]; } } return mbutton; } return base.ConvertFrom(context, culture, value); }
public void Measure () { Button b = new Button (); b.Measure (new Size (double.PositiveInfinity, double.PositiveInfinity)); Assert.AreEqual (b.DesiredSize.Width, 0, "Width"); Assert.AreEqual (b.DesiredSize.Height, 0, "Height"); b.Measure (new Size (double.PositiveInfinity, 10)); Assert.AreEqual (b.DesiredSize.Width, 0, "Width 2"); Assert.AreEqual (b.DesiredSize.Height, 0, "Height 2"); b.Measure (new Size (double.PositiveInfinity, 7)); Assert.AreEqual (b.DesiredSize.Width, 0, "Width 3"); Assert.AreEqual (b.DesiredSize.Height, 0, "Height 3"); b.Measure (new Size (7, 7)); Assert.AreEqual (b.DesiredSize.Width, 0, "Width 4"); Assert.AreEqual (b.DesiredSize.Height, 0, "Height 4"); }