I’ve always wanted to make a clock in WPF

Description

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);
    }));
}

Tag:

C4FNews

The Discussion

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.