using Container.Common; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; 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.Shapes; namespace Container.Win { /// /// CountDown.xaml 的交互逻辑 /// public partial class CountDown : Window { public CountDown() { InitializeComponent(); } Class_Log log = new Class_Log(); private void Window_Loaded(object sender, RoutedEventArgs e) { LoadPics(); } private void LoadPics() { try { Storyboard _storyboard = new Storyboard(); for (int i = 0; i < 220; i++) { ObjectAnimationUsingKeyFrames oauf = new ObjectAnimationUsingKeyFrames(); //ObjectAnimationUsingKeyFrames 可以对指定 Duration 内的一组 KeyFrames 中的 Object 属性值进行动画处理 BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); string name = i.ToString().PadLeft(5, '0'); bitmap.UriSource = new Uri("pack://application:,,,/Container;component/image/CountDowmImage/倒计时透明度_" + name + ".png"); bitmap.CacheOption = BitmapCacheOption.Default; bitmap.EndInit(); ImageBrush imgBrush = new ImageBrush(bitmap); //读取图片文件 DiscreteObjectKeyFrame dokf = new DiscreteObjectKeyFrame(); //DiscreteObjectKeyFrame 通过使用离散内插,可以在前一个关键帧的 Object 值及其自己的 Value 之间进行动画处理。 dokf.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(i * 30)); //KeyTime 获取或设置应到达关键帧的目标 Value 的时间 //这里每隔40毫秒设置一张图片,也就是每秒1000/40=25帧 dokf.Value = imgBrush; oauf.KeyFrames.Add(dokf); Storyboard.SetTargetProperty(oauf, new PropertyPath("(Rectangle.Fill)")); //把动画应用到窗体的Rectangle中 Storyboard.SetTarget(oauf, RectDisImage); //RectDis是Rectangle的名称 _storyboard.Children.Add(oauf); //把ObjectAnimationUsingKeyFrames动画添加到Storyboard中 } _storyboard.Completed += new EventHandler(time_Completed); //_storyboard.RepeatBehavior = RepeatBehavior.Forever; _storyboard.Begin(); } catch (Exception ex) { log.WriteLogFile(ex.Message, "error"); } } void time_Completed(object sender, EventArgs e) { WindowViewNew window = new WindowViewNew(); window.Show(); this.Close(); } } }