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


C# Button.UpdateLayout方法代码示例

本文整理汇总了C#中System.Windows.Controls.Button.UpdateLayout方法的典型用法代码示例。如果您正苦于以下问题:C# Button.UpdateLayout方法的具体用法?C# Button.UpdateLayout怎么用?C# Button.UpdateLayout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.Button的用法示例。


在下文中一共展示了Button.UpdateLayout方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestImplicitStyleButton_oneStyleInVisualTree_onStyleInAppResources

		public void TestImplicitStyleButton_oneStyleInVisualTree_onStyleInAppResources ()
		{
			Style style1 = new Style { TargetType = typeof (Button) };
			Setter setter = new Setter (FrameworkElement.WidthProperty, 100.0);
			style1.Setters.Add (setter);

			Style style2 = new Style { TargetType = typeof (Button) };
			setter = new Setter (FrameworkElement.HeightProperty, 100.0);
			style2.Setters.Add (setter);

			Button b = new Button ();
			b.Resources.Add (typeof (Button), style1);

			Application.Current.Resources.Remove (typeof (Button));
			Application.Current.Resources.Add (typeof (Button), style2);

			Assert.IsTrue (Double.IsNaN (b.Height), "1");

			CreateAsyncTest (b,  () => {
					b.UpdateLayout ();

					Assert.AreEqual (100.0, b.Width, "2");
					Assert.IsTrue (Double.IsNaN (b.Height), "3");

					Application.Current.Resources.Remove (typeof (Button));
				});
		}
开发者ID:dfr0,项目名称:moon,代码行数:27,代码来源:StyleTest_Implicit.cs

示例2: SetStyle

        public static void SetStyle(Button button, Brush unpressedBrush, Brush mouseOverBrush, Brush pressedBrush, Brush unpressedPen, Brush mouseOverPen, Brush pressedPen, double radius, bool bShine)
        {
            Initialise("Button1");

            ControlTemplate template = null;
            foreach (Setter setter in style.Setters)
            {
                if (setter.Property == Button.TemplateProperty)
                {
                    template = (ControlTemplate)setter.Value;
                    foreach (Trigger trigger in template.Triggers)
                    {
                        if (trigger.Property == Button.IsMouseOverProperty)
                        {
                            foreach (Setter setter1 in trigger.Setters)
                            {
                                if (setter1.TargetName == "buttonBackground")
                                {
                                    setter1.Value = mouseOverBrush;
                                }
                                else if (setter1.TargetName == "contentPresenter")
                                {
                                    setter1.Value = mouseOverPen;
                                }
                            }
                        }
                        else if (trigger.Property == Button.IsPressedProperty)
                        {
                            foreach (Setter setter1 in trigger.Setters)
                            {
                                if (setter1.TargetName == "buttonBackground")
                                {
                                    setter1.Value = pressedBrush;
                                }
                                else if (setter1.TargetName == "contentPresenter")
                                {
                                    setter1.Value = pressedPen;
                                }
                            }
                        }
                    }
                }
            }
            button.Width = button.ActualWidth;
            button.Height = button.ActualHeight;
            button.Background = unpressedBrush;
            button.Foreground = unpressedPen;
            button.FocusVisualStyle = null;
            button.Style = style;

            button.UpdateLayout();
            Rectangle rectangle = (Rectangle)button.Template.FindName("buttonBackground", button);
            rectangle.RadiusX = radius;
            rectangle.RadiusY = radius;
            rectangle = (Rectangle)button.Template.FindName("buttonShine", button);
            rectangle.Visibility = bShine ? Visibility.Visible : Visibility.Hidden;
            rectangle.RadiusX = radius * 0.67;
            rectangle.RadiusY = radius * 0.67;
        }
开发者ID:litdev1,项目名称:LitDev,代码行数:59,代码来源:Styles.cs


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