Beispiel #1
0
        private void CountdownTimer_Tick(object sender, EventArgs e)
        {
            TimeSpan diff = countdownEnd - DateTime.Now;

            if (diff.TotalMilliseconds <= 0)
            {
                countdownTimer.Stop();

                DoubleAnimation fadeOut = new DoubleAnimation(0.0, TimeSpan.FromMilliseconds(2500));
                CountdownViewBox.BeginAnimation(OpacityProperty, fadeOut);

                return;
            }

            CountdownTextBox.Text = Math.Floor(diff.TotalMinutes).ToString("00") + ":" + diff.Seconds.ToString("00");
        }
Beispiel #2
0
        public void SetCountdown(double seconds)
        {
            countdownTimer.Stop();

            countdownEnd = DateTime.Now.AddSeconds(seconds);
            CountdownTimer_Tick(null, null);

            DoubleAnimation fadeIn = new DoubleAnimation(1.0, TimeSpan.FromMilliseconds(2500));

            fadeIn.Completed += (s, e) =>
            {
                countdownEnd = DateTime.Now.AddSeconds(seconds);
                countdownTimer.Start();
            };

            CountdownViewBox.BeginAnimation(OpacityProperty, fadeIn);
        }