Set a timer for a Windows 8 phone. An application using XAML with C #

I am developing an application for Windows Phone 8.

I need to add a countdown function to my application.

as when launching the application. Timer value Show 60,59,58 .... 0

When 0 Reach Show Msg Timeout.

I searched on Google, but I have no idea. [Maybe this is my mistake not in the right search]

I am trying to use the following code that shows date and time values ​​such as [3/12/2014 6:22:10 PM]

C # code

 public SensorTwo()
    {
        InitializeComponent();
        DispatcherTimer newTimer = new DispatcherTimer();
        newTimer.Interval = TimeSpan.FromSeconds(1);
        newTimer.Tick += OnTimerTick;
        newTimer.Start();
    }

 void OnTimerTick(Object sender, EventArgs args)
    {
        clock.Text = DateTime.Now.ToString();
    }

XAML CODE

<TextBlock Foreground="Red" FontSize="22"  Name="clock" Width="350" Height="50" HorizontalAlignment="Center" VerticalAlignment="Bottom"></TextBlock>

any help or tell me to complete this functionality ...

+4
source share
3 answers
//make global declaration of a counter variable 


 int counter =60;    
    void OnTimerTick(Object sender, EventArgs args)
       {       
         counter --;
         if(counter<0)
         {
          newTimer.Stop();
          counter=60;
         }
        else
         {
          clock.Text =counter.ToString();
         }
       }
+2
source

, reset

TimeSpan counter = new TimeSpan(0, 0, 60);

OnTimerTick()

counter -= TimeSpan.FromSeconds(1);   
clock.Text = counter.Seconds;

,

+1

clock.Text = DateTime.Now.ToString( "ss" );

0
source

Source: https://habr.com/ru/post/1531332/


All Articles