WPF 动画显示控件
程序员文章站
2022-02-14 11:10:45
当我们要显示一个控件的时候,不仅仅要显示这个控件,还要有动画的效果。 主要用到了doubleanimation类。 public static void showanimation(object co...
当我们要显示一个控件的时候,不仅仅要显示这个控件,还要有动画的效果。
主要用到了doubleanimation类。
public static void showanimation(object control) { type type = control.gettype(); switch (type.name) { case "border": { border newborder = (border)control; #region 高、宽变化动画 doubleanimation widthanimation = new doubleanimation(0, newborder.width, new duration(timespan.fromseconds(0.5))); newborder.beginanimation(border.widthproperty, widthanimation, handoffbehavior.compose); doubleanimation heightanimation = new doubleanimation(0, newborder.height, new duration(timespan.fromseconds(0.5))); newborder.beginanimation(border.heightproperty, heightanimation, handoffbehavior.compose); #endregion } break; default: break; } }
调用的时候也简单。
private void button_click(object sender, routedeventargs e) { bord1.visibility = visibility.visible; showanimation(bord1); }
效果如下:
上一篇: WPF——菜单栏及TabControl
下一篇: C# 彻底搞懂async/await