using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace JianGongYun.TRTC.Components
{
    /// <summary>
    /// CountdownControl.xaml 的交互逻辑
    /// </summary>
    public partial class CountdownControl : UserControl
    {
        private Grid grid = null;
        private Window wm;
        public CountdownControl(Grid _grid, Window _wm)
        {
            InitializeComponent();
            grid = _grid;
            wm = _wm;
        }

        /// <summary>
        /// 创建动画执行对象
        /// </summary>
        private Storyboard sb = null;
        /// <summary>
        /// 给文本框赋值
        /// </summary>
        private string txtValue = string.Empty;
        public string TxtValue
        {
            get { return txtValue; }
            set { txtValue = value; this.tb.Text = txtValue; }
        }
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            //创建动画对象实例
            sb = new Storyboard();
            //ScaleX缩放动画
            //DoubleAnimation daX = new DoubleAnimation();
            //daX.Duration = TimeSpan.FromSeconds(0.6);
            //daX.From = 1.35;
            //daX.To = 1;
            //Storyboard.SetTarget(daX, this);
            //Storyboard.SetTargetProperty(daX, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"));
            ////ScaleY缩放动画
            //DoubleAnimation daY = new DoubleAnimation();
            //daY.Duration = TimeSpan.FromSeconds(0.6);
            //daY.From = 1.35;
            //daY.To = 1;
            //Storyboard.SetTarget(daY, this);
            //Storyboard.SetTargetProperty(daY, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"));
            //Opacity变换动画
            DoubleAnimation daO = new DoubleAnimation();
            daO.Duration = TimeSpan.FromSeconds(0.6);
            daO.From = 0;
            daO.To = 1;
            Storyboard.SetTarget(daO, this);
            Storyboard.SetTargetProperty(daO, new PropertyPath("(Opacity)"));
            //sb.Children.Add(daX);
            //sb.Children.Add(daY);
            sb.Children.Add(daO);

            DoubleAnimation daTop2 = new DoubleAnimation();
            daTop2.BeginTime = TimeSpan.FromSeconds(0.7);
            daTop2.Duration = TimeSpan.FromSeconds(0.2);
            daTop2.EasingFunction = new BounceEase() { Bounces = 10, EasingMode = EasingMode.EaseInOut };
            Storyboard.SetTarget(daTop2, wm);
            Storyboard.SetTargetProperty(daTop2, new PropertyPath("(Top)"));
            sb.Children.Add(daTop2);
            sb.Completed += new EventHandler(sb_Completed);
            sb.Begin(this, true);
        }
        private void sb_Completed(object sender, EventArgs e)
        {
            //解除绑定 
            sb.Remove(this);
            sb.Children.Clear();
            grid.Children.Clear();
        }
    }
}
