I’ve always wanted to make a clock in WPF

Sign in to queue


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



The Discussion

Add Your 2 Cents