locked
Christmas Countdown Help RRS feed

  • Question

  • expression blend 4 c# noob

    i have my piece of code for the count down perfect, when i run the application it shows you, days, hours, minutes and seconds until Christmas. All of that works fine but it doesnt update every sencond and thats what the problem is. I want the code to update every second so the "secons until christmas" keeps changing, then the minutes and so on.

    How do i do this?

    Friday, November 12, 2010 6:10 PM

Answers

  • You need to create a timer, like this:

     

    public Screen_1()
    		{
    			// Required to initialize variables
    			InitializeComponent();
    
    			var timer = new System.Windows.Threading.DispatcherTimer();
    			timer.Interval = TimeSpan.FromSeconds(1.0);
    			timer.Tick += timer_Tick;
    			timer.Start();
    
    		}
    
    		void timer_Tick(object sender, EventArgs e)
    		{
    			// Update the UI here, or the model the UI is bound to.
    		}
    

     

    • Proposed as answer by Chuck HaysModerator Friday, November 12, 2010 7:03 PM
    • Marked as answer by apprentice97 Friday, November 12, 2010 7:51 PM
    • Unmarked as answer by apprentice97 Friday, November 12, 2010 8:00 PM
    • Unproposed as answer by apprentice97 Friday, November 12, 2010 8:00 PM
    • Marked as answer by apprentice97 Saturday, November 13, 2010 8:12 PM
    Friday, November 12, 2010 7:03 PM
    Moderator

All replies

  • You need to create a timer, like this:

     

    public Screen_1()
    		{
    			// Required to initialize variables
    			InitializeComponent();
    
    			var timer = new System.Windows.Threading.DispatcherTimer();
    			timer.Interval = TimeSpan.FromSeconds(1.0);
    			timer.Tick += timer_Tick;
    			timer.Start();
    
    		}
    
    		void timer_Tick(object sender, EventArgs e)
    		{
    			// Update the UI here, or the model the UI is bound to.
    		}
    

     

    • Proposed as answer by Chuck HaysModerator Friday, November 12, 2010 7:03 PM
    • Marked as answer by apprentice97 Friday, November 12, 2010 7:51 PM
    • Unmarked as answer by apprentice97 Friday, November 12, 2010 8:00 PM
    • Unproposed as answer by apprentice97 Friday, November 12, 2010 8:00 PM
    • Marked as answer by apprentice97 Saturday, November 13, 2010 8:12 PM
    Friday, November 12, 2010 7:03 PM
    Moderator
  • thanks, it works perfectly, but, some of the numbers flash randomly. Is there any way of fixing this?
    Friday, November 12, 2010 7:55 PM
  • I'd need to see more of the code. Could you post the xaml and code behind file?
    Friday, November 12, 2010 10:34 PM
    Moderator
  • i fixed it! all i had to do was round the numbers with Math.Floor(). Thank You!
    Saturday, November 13, 2010 8:12 PM