当前位置: 首页>>代码示例>>C#>>正文


C# Button.Measure方法代码示例

本文整理汇总了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;
        }
开发者ID:rbirkby,项目名称:mscui,代码行数:28,代码来源:TimeAndYGraphBase.cs

示例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);
        }
开发者ID:jcrout,项目名称:WPF-MVVM-Minesweeper,代码行数:62,代码来源:MessageButtonConverter.cs

示例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");
		}
开发者ID:JianwenSun,项目名称:mono-soc-2007,代码行数:16,代码来源:ButtonTest.cs


注:本文中的System.Windows.Controls.Button.Measure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。