关闭

WPF的简单关闭动画特效

标签: WPF特效动画
748人阅读 评论(0) 收藏 举报
分类:

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

  页面代码:

<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();
        }
 }


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:48189次
    • 积分:695
    • 等级:
    • 排名:千里之外
    • 原创:11篇
    • 转载:37篇
    • 译文:0篇
    • 评论:8条
    文章分类