WPF 動畫顯示控件
阿新 • • 發佈:2018-09-26
avi code () 一個 log case private 還要 obj 原文:WPF 動畫顯示控件
當我們要顯示一個控件的時候,不僅僅要顯示這個控件,還要有動畫的效果。
主要用到了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 動畫顯示控件