Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Windows Phone 7 – A Simple Clock App in 10-15 Minutes

DZone's Guide to

Windows Phone 7 – A Simple Clock App in 10-15 Minutes

· Mobile Zone
Free Resource

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

I have started to learn WP7 through reading an e-book, and here I would like to share the Simple clock example which I have practiced just now. Its very easy to understand and implement.


MainPage.xaml

 <grid x:name="ContentPanel" grid.row="1" margin="12,0,12,0">
            <textbox height="72" horizontalalignment="Center" name="txtTimer" verticalalignment="Center" width="345">
        </textbox></grid>

Below is the entire code file. And yes include System.Windows.Threading namespace because DispatcherTimer resides in it and its not included by default. The constructor initializes the DispatcherTimer, instructing it to call OnTimerTick once every second. The event handler onTimerTick simply converts the current time to a string to set it to the TextBlock.

MainPage.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Threading;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace _1OrientationDemo
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            DispatcherTimer timer  = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += OnTimerTick;
            timer.Start();
        }

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

    }
}

And that's it!

 

Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda

Topics:

Published at DZone with permission of Paresh Mayani. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}