WPF的简单关闭动画特效

运行是动态的没办法截图,这个是关闭窗口时有一个关闭的动画!

  页面代码:

< Window
 xmlns=
"http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x=
"http://schemas.microsoft.com/winfx/2006/xaml"
 x:Class=
"LianXi.Window10"
 x:Name=
"Window"
 Title=
"Window10"
 Width=
"640"  Height= "480"  Closing= "Window_Closing">

    < Grid x:Name= "LayoutRoot">
         < /Grid>
< /Window>

  后台代码:

/// <summary>
 /// Window10.xaml 的交互逻辑
 /// </summary>
 public partial class Window10 : Window
 {
  public Window10()
  {
   this.InitializeComponent();
   
   // 在此点之下插入创建对象所需的代码。
  }
        bool _closinganimation = true;
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = _closinganimation;
            _closinganimation = false;
           // base.OnClosing(e);

            System.Windows.Media.Animation.Storyboard sb = new System.Windows.Media.Animation.Storyboard();
            System.Windows.Media.Animation.DoubleAnimation dh = new System.Windows.Media.Animation.DoubleAnimation();
            System.Windows.Media.Animation.DoubleAnimation dw = new System.Windows.Media.Animation.DoubleAnimation();
            System.Windows.Media.Animation.DoubleAnimation dop = new System.Windows.Media.Animation.DoubleAnimation();
            dop.Duration = dh.Duration = dw.Duration = sb.Duration = new Duration(new TimeSpan(0, 0, 2));
            dop.To = dh.To = dw.To = 0;
            System.Windows.Media.Animation.Storyboard.SetTarget(dop, this);
            System.Windows.Media.Animation.Storyboard.SetTarget(dh, this);
            System.Windows.Media.Animation.Storyboard.SetTarget(dw, this);
            System.Windows.Media.Animation.Storyboard.SetTargetProperty(dop, new PropertyPath("Opacity", new object[] { }));
            System.Windows.Media.Animation.Storyboard.SetTargetProperty(dh, new PropertyPath("Height", new object[] { }));
            System.Windows.Media.Animation.Storyboard.SetTargetProperty(dw, new PropertyPath("Width", new object[] { }));
            sb.Children.Add(dh);
            sb.Children.Add(dw);
            sb.Children.Add(dop);
            sb.Completed += new EventHandler(sb_Completed); //(a, b) => { this.Close(); };
            sb.Begin();
           
        }

        void sb_Completed(object sender, EventArgs e)
        {
             this.Close();
        }
 }


来自: http://www.silverlightchina.net/html/study/WPF/2011/1122/11956.html

你可能感兴趣的:(动画,WPF特效)