Click here to Skip to main content
13,594,656 members
Click here to Skip to main content
Add your own
alternative version


22 bookmarked
Posted 19 Nov 2008
Licenced CPOL

Analog Clock in Expression Blend 2

, 19 Nov 2008
Rate this:
Please Sign up or sign in to vote.
A simple analog clock in Expression Blend 2



This is a simple WPF App in Expression Blend 2 SP1 that shows you how we can create an analog clock with some effects like Shadow and Blur.
I haven't used any images in this project and everything that you see has been created with XAML code.


Some days ago, I created another very simple anolog clock in Visual Studio 2008. If you think this project is a little difficult, you can see that first.
These training videos can also help you to work with Expression Blend. I've used them.

Using the Code

In Expression Blend, we don't need to edit XAML code manually (typically), but I think that if we know how the XAML code works, it helps us to create a better WPF app.

Well, the difficult part of this project is creating three pointers for our clock with rotation ability. For that, I've used this XAML code:

  <Rectangle Fill="#FFDCDCDC" Margin="86.169,8,85.904,88.555" 

  Stroke="#FFDCDCDC" StrokeDashCap="Round" 

  StrokeEndLineCap="Round" StrokeLineJoin="Round" 

  StrokeStartLineCap="Round" StrokeThickness="1" 

  RadiusX="1" RadiusY="1" Opacity="0.8" 

  x:Name="rectangleSecond" RenderTransformOrigin="0.5,1" 

				<ScaleTransform ScaleX="1" ScaleY="1"/>
				<SkewTransform AngleX="0" AngleY="0"/>
				<RotateTransform x:Name="secondHand" Angle="0"/>
				<TranslateTransform X="0" Y="0"/>

Now we can rotate this pointer easily with this C# code:

secondHand.Angle = DateTime.Now.Second * 6;

That was very easy. Wasn't it?

Now we use a simple method for rotating our three pointers:

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

For further learning about the above method, you can see here.
That's all.


  • 20th November, 2008: First post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Mohammad Dayyan
Iran (Islamic Republic of) Iran (Islamic Republic of)
No Biography provided

You may also be interested in...

Comments and Discussions

Questionadding Code Pin
Member 867797425-Feb-12 19:49
memberMember 867797425-Feb-12 19:49 
GeneralNice clock. Simple and pretty Pin
Roger Bacon21-Apr-09 11:22
memberRoger Bacon21-Apr-09 11:22 
GeneralInvalid tags Pin
berzie24-Jan-09 19:31
memberberzie24-Jan-09 19:31 
GeneralMy vote of 1 Pin
Country Man27-Nov-08 1:58
memberCountry Man27-Nov-08 1:58 
Generalnice clock Pin
christoph braendle19-Nov-08 22:04
memberchristoph braendle19-Nov-08 22:04 
GeneralRe: nice clock Pin
Mohammad Dayyan20-Nov-08 4:10
memberMohammad Dayyan20-Nov-08 4:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180621.3 | Last Updated 19 Nov 2008
Article Copyright 2008 by Mohammad Dayyan
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid