I'm trying to make a C#/WPF app with a date countdown. The problem I'm having is I'm trying to use the t.days, t.minutes, t.seconds variables in textblocks and then use a timer to count them down. I just have no idea on how to implement this.
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.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace WpfApplication2
{
public partial class MainWindow : Window
{
private int _time;
private DispatcherTimer _countdownTimer;
public MainWindow()
{
this.InitializeComponent();
DateTime eventTime = DateTime.Parse("1/20/2012 12:00:01 AM");
DateTime startDate = DateTime.Now;
TimeSpan t = eventTime - startDate;
string countDown = string.Format("{0} Days, {1} Hours, {2} Minutes, {3} Seconds til launch.", t.Days, t.Hours, t.Minutes, t.Seconds);
_countdownTimer = new DispatcherTimer();
_countdownTimer.Interval = new TimeSpan(0,0,1);
_countdownTimer.Tick += new EventHandler(CountdownTimerStep);
_countdownTimer.Start();
}
}
}
Basically what I'm trying to do: I have three textblocks. One for days, one for minutes, and one for seconds. I want to use the timer to countdown the days, minutes, and seconds in a live format. Obviously when the seconds reach zero it'll have to subtract 1 from the minute textblock and reset the seconds textblock. Same for the others.
Anyone have any ideas or previously used code?


Sign In
Create Account


Back to top









