本文整理汇总了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));
});
}
示例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;
}