I’ve always wanted to make a clock in WPF
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);
}));
}
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