DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

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

Paresh  Mayani user avatar by
Paresh Mayani
·
Apr. 12, 12 · Interview
Like (0)
Save
Tweet
Share
5.81K Views

Join the DZone community and get the full member experience.

Join For Free

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!

 

Windows Phone Clock (cryptography) app

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

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Tech Layoffs [Comic]
  • Top 5 PHP REST API Frameworks
  • The Importance of Delegation in Management Teams
  • Beginners’ Guide to Run a Linux Server Securely

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: