Clock in windows phone 8

In this article,  i will use  DispatcherTimer class for creating timer control. Using interval property of this class, i will set the increment counter. After set the interval you can call tick event of this class. On tick event you can take current date and time. .
To create a new app in windows phone 8, the steps are listed below:
Create a new project by going through File | New Project | Windows Phone Application - Visual C#. Give a desired project name( World Clock is my app name).
create a new app in windows phone 8

From Solution Explorer, open MainPage.xaml file. (If Solution Explorer window is currently not opened then open it via View>>Other Windows>>Solution Explorer).
Inside Control Panel code fragment, add following code to create world clock app.

Source code (MainPage.xaml)

 <TextBlock HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="436" Height="63" x:Name="label1" FontSize="30" Grid.ColumnSpan="2"/>

Code behind 

   DispatcherTimer t1 = new DispatcherTimer();
    t1.Interval = TimeSpan.FromSeconds(1);
            t1.Tick += OnTick;

  void OnTick(Object sender, EventArgs args)
            label1.Text = DateTime.Now.ToString();

Code Generate the following output

Clock in windows phone 8

Posted on by Jacob Lefore | No comments


Post a Comment