I’ve always wanted to make a clock in WPF

Published 23 September 08 11:36 AM | Coding4Fun 

image[1] Mohammad Dayyan created a great example of an analog clock in WPF.  It shows how to do a few basics of WPF such as XAML, rotation transforms and using the Dispatcher object to update the user interface.

Here is a quick bit of sample code from Mohammad’s application.

void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
    this.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
    {
        secondHand.Angle = DateTime.Now.Second * 6;
        minuteHand.Angle = DateTime.Now.Minute * 6;
        hourHand.Angle = (DateTime.Now.Hour * 30) + (DateTime.Now.Minute * 0.5);
    }));
}
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# jackbond said on September 23, 2008 5:21 PM:

This is a little more in the spirit of WPF by using animations to update the hands, and well, it just looks a little slicker (especially in night mode) http://blogs.msdn.com/synergist/archive/2008/05/24/beauty-with-silverlight.aspx

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

Search

This Blog

Syndication

Page view tracker