本文整理汇总了C#中System.Windows.Controls.Button.Measure方法的典型用法代码示例。如果您正苦于以下问题:C# Button.Measure方法的具体用法?C# Button.Measure怎么用?C# Button.Measure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.Button
的用法示例。
在下文中一共展示了Button.Measure方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetArrowButtonSize
/// <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;
}
示例2: ConvertFrom
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);
}
示例3: Measure
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");
}