Skip to content

Instantly share code, notes, and snippets.

@eternaltung
Created April 24, 2013 13:27
Show Gist options
  • Save eternaltung/5452115 to your computer and use it in GitHub Desktop.
Save eternaltung/5452115 to your computer and use it in GitHub Desktop.
using System;
using System.Windows;
using System.Windows.Media.Animation;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
Storyboard sb_timer = new Storyboard() { Duration = TimeSpan.FromSeconds(1) };
int sec = 5;
public MainWindow()
{
InitializeComponent();
sb_timer.Completed += sb_timer_Completed;
sb_timer.Begin();
}
void sb_timer_Completed(object sender, EventArgs e)
{
if (sec > 0)
{
sec--;
timerText.Text = sec.ToString(); //timerText是介面上的一個TextBlock
sb_timer.Begin();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment