Introduction
Step 1

Create a new project in Visual Studio 2012 and select "Silverlight Application".
Step 2

Open MainPage.xaml and add the following code.
  1. <UserControl x:Class="SilverlightAnalogClock.MainPage"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. mc:Ignorable="d"
  7. d:DesignHeight="300" d:DesignWidth="400">
  8. <Grid x:Name="LayoutRoot" Background="White">
  9. </Grid>
  10. </UserControl>
Step 3

Open MainPage.xaml.cs and add the following code.
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Documents;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Animation;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Shapes;
  13. namespace SilverlightAnalogClock
  14. {
  15. public partial class MainPage : UserControl
  16. {
  17. public Canvas ClockArea = null;
  18. public Rectangle secondHand = null;
  19. public Rectangle minuteHand = null;
  20. public Rectangle hourHand = null;
  21. public RotateTransform secondHandRotate = null;
  22. public RotateTransform minuteHandRotate = null;
  23. public RotateTransform hourHandRotate = null;
  24. public Ellipse outerCircle = null;
  25. public Point centerPoint;
  26. public double HEIGHT = 0;
  27. public double WIDTH = 0;
  28. public double RADIUS = 0;
  29. public MainPage()
  30. {
  31. InitializeComponent();
  32. ClockArea = new Canvas()
  33. {
  34. Width = 300,
  35. Height = 300,
  36. HorizontalAlignment = HorizontalAlignment.Left,
  37. VerticalAlignment = VerticalAlignment.Top
  38. };
  39. ClockArea.SetValue(Grid.RowProperty, 0);
  40. ClockArea.SetValue(Grid.ColumnProperty, 0);
  41. ClockArea.Margin = new Thickness(0, 0, 0, 0);
  42. this.LayoutRoot.Children.Add(ClockArea);
  43. WIDTH = ClockArea.Width;
  44. HEIGHT = ClockArea.Height;
  45. centerPoint.X = (WIDTH/2);
  46. centerPoint.Y = (HEIGHT/2);
  47. RADIUS = 400;
  48. DrawClockFace();
  49. Point TOPPOINT = new Point(0, 0);
  50. DrawMinuteHand();
  51. DrawSecondHand();
  52. DrawHourHand();
  53. DrawCenterCircle();
  54. //Start the Clock
  55. ClockStart();
  56. }
  57. public void ClockStart()
  58. {
  59. // Create and Start the Thread Timer
  60. System.Windows.Threading.DispatcherTimer clockTimer = new System.Windows.Threading.DispatcherTimer();
  61. clockTimer.Interval = new TimeSpan(0, 0, 0, 0, 1000);
  62. clockTimer.Tick += new EventHandler(Clock_Tick);
  63. clockTimer.Start();
  64. }
  65. // Get and Set the Angles of Each Hand at every Clock Ticks
  66. public void Clock_Tick(object o, EventArgs sender)
  67. {
  68. double hourRotateValue = Convert.ToDouble(DateTime.Now.Hour.ToString());
  69. double minuteRotateValue = Convert.ToDouble(DateTime.Now.Minute.ToString());
  70. double secondRotateValue = Convert.ToDouble(DateTime.Now.Second.ToString());
  71. hourRotateValue = (hourRotateValue + minuteRotateValue / 60) * 30;
  72. minuteRotateValue = (minuteRotateValue + secondRotateValue / 60) * 6;
  73. secondRotateValue = Convert.ToDouble(DateTime.Now.Second.ToString()) * 6;
  74. minuteHandRotate.Angle = minuteRotateValue;
  75. hourHandRotate.Angle = hourRotateValue;
  76. secondHandRotate.Angle = secondRotateValue;
  77. }
  78. // Draw Center Circle
  79. public void DrawCenterCircle()
  80. {
  81. Ellipse centerCircle = new Ellipse()
  82. {
  83. Width = 10,
  84. Height = 10,
  85. Stroke = new SolidColorBrush(Colors.Red),
  86. Fill = new SolidColorBrush(Colors.Red),
  87. HorizontalAlignment = HorizontalAlignment.Center,
  88. VerticalAlignment = VerticalAlignment.Center
  89. };
  90. centerCircle.SetValue(Grid.RowProperty, 0);
  91. centerCircle.SetValue(Grid.ColumnProperty, 0);
  92. Canvas.SetLeft(centerCircle, (WIDTH / 2) - (centerCircle.Width / 2));
  93. Canvas.SetTop(centerCircle, (HEIGHT / 2) - (centerCircle.Height / 2));
  94. ClockArea.Children.Add(centerCircle);
  95. }
  96. // Draw Clock Face
  97. public void DrawClockFace()
  98. {
  99. int smallCircle = 5;
  100. Color c = Colors.Blue;
  101. int p = 0;
  102. // Draw Shadow of Outer Circle
  103. Ellipse outerCircleShadow = new Ellipse()
  104. {
  105. Width = (WIDTH),
  106. Height = (WIDTH),
  107. Stroke = new SolidColorBrush(Colors.Gray),
  108. StrokeThickness = 5,
  109. HorizontalAlignment = HorizontalAlignment.Center,
  110. VerticalAlignment = VerticalAlignment.Center
  111. };
  112. outerCircleShadow.SetValue(Grid.RowProperty, 0);
  113. outerCircleShadow.SetValue(Grid.ColumnProperty, 0);
  114. Canvas.SetLeft(outerCircleShadow, (WIDTH / 2) - (outerCircleShadow.Width / 2) + 6.5);
  115. Canvas.SetTop(outerCircleShadow, (HEIGHT / 2) - (outerCircleShadow.Height / 2) + 6.5);
  116. ClockArea.Children.Add(outerCircleShadow);
  117. // Draw Outer Circle
  118. outerCircle = new Ellipse()
  119. {
  120. Width = (WIDTH ),
  121. Height = (WIDTH),
  122. Stroke = new SolidColorBrush(Colors.Black),
  123. StrokeThickness = 5,
  124. HorizontalAlignment = HorizontalAlignment.Center,
  125. VerticalAlignment = VerticalAlignment.Center
  126. };
  127. outerCircle.SetValue(Grid.RowProperty, 0);
  128. outerCircle.SetValue(Grid.ColumnProperty, 0);
  129. Canvas.SetLeft(outerCircle, (WIDTH / 2) - (outerCircle.Width / 2) + 4.5);
  130. Canvas.SetTop(outerCircle, (HEIGHT / 2) - (outerCircle.Height / 2) + 4.5);
  131. ClockArea.Children.Add(outerCircle);
  132. outerCircle.Fill = new LinearGradientBrush()
  133. {
  134. EndPoint = new Point(1, 0),
  135. GradientStops = new GradientStopCollection()
  136. {
  137. new GradientStop() { Color = Colors.White, Offset = 0 },
  138. new GradientStop() { Color = Colors.Gray, Offset = 0.5 },
  139. new GradientStop() { Color = Colors.White, Offset = 1 }
  140. }
  141. };
  142. int clockDigits = 3;
  143. double rad = (WIDTH/2) - 10.0f;
  144. // 60 Innner Dots as Small Circle
  145. for (double i = 0.0; i < 360.0; i += 6)
  146. {
  147. double angle = i * System.Math.PI / 180;
  148. int x = (int)(centerPoint.X + rad * System.Math.Cos(angle));
  149. int y = (int)(centerPoint.Y + rad * System.Math.Sin(angle));
  150. if (p % 5 == 0)
  151. {
  152. smallCircle = 10;
  153. c = Colors.Orange;
  154. }
  155. else
  156. {
  157. smallCircle = 5;
  158. c = Colors.Blue;
  159. }
  160. if (p % 15 == 0)
  161. {
  162. TextBlock tb = new TextBlock();
  163. tb.Text = clockDigits.ToString();
  164. tb.FontSize = 24;
  165. tb.SetValue(Grid.RowProperty, 0);
  166. tb.SetValue(Grid.ColumnProperty, 0);
  167. Canvas.SetLeft(tb, x );
  168. Canvas.SetTop(tb, y);
  169. if (clockDigits == 3)
  170. {
  171. Canvas.SetLeft(tb, x - 20);
  172. Canvas.SetTop(tb, y - 10);
  173. }
  174. if (clockDigits == 6)
  175. {
  176. Canvas.SetLeft(tb, x);
  177. Canvas.SetTop(tb, y - 30);
  178. }
  179. if (clockDigits == 9)
  180. {
  181. Canvas.SetLeft(tb, x + 15);
  182. Canvas.SetTop(tb, y - 10);
  183. }
  184. if (clockDigits == 12)
  185. {
  186. Canvas.SetLeft(tb, x - 10);
  187. Canvas.SetTop(tb, y + 5 );
  188. }
  189. ClockArea.Children.Add(tb);
  190. clockDigits = clockDigits + 3;
  191. }
  192. p++;
  193. Ellipse innerPoints = new Ellipse()
  194. {
  195. Width = smallCircle,
  196. Height = smallCircle,
  197. Stroke = new SolidColorBrush(c),
  198. Fill = new SolidColorBrush(c),
  199. HorizontalAlignment = HorizontalAlignment.Center,
  200. VerticalAlignment = VerticalAlignment.Center
  201. };
  202. innerPoints.SetValue(Grid.RowProperty, 0);
  203. innerPoints.SetValue(Grid.ColumnProperty, 0);
  204. Canvas.SetLeft(innerPoints, x);
  205. Canvas.SetTop(innerPoints, y);
  206. ClockArea.Children.Add(innerPoints);
  207. }
  208. }
  209. // Draw the Second Hand
  210. public void DrawSecondHand()
  211. {
  212. double handLength = (HEIGHT / 2) - 20;
  213. secondHand = new Rectangle()
  214. {
  215. Width = 1,
  216. Height = handLength,
  217. Stroke = new SolidColorBrush(Colors.Red),
  218. Fill = new SolidColorBrush(Colors.Red),
  219. HorizontalAlignment = HorizontalAlignment.Center,
  220. VerticalAlignment = VerticalAlignment.Center
  221. };
  222. secondHand.SetValue(Grid.RowProperty, 0);
  223. secondHand.SetValue(Grid.ColumnProperty, 0);
  224. //Add Rotate Transformation
  225. secondHandRotate = new RotateTransform();
  226. secondHandRotate.Angle = 0;
  227. //Set Center for Rotation
  228. secondHandRotate.CenterX = Canvas.GetLeft(secondHand);
  229. secondHandRotate.CenterY = secondHand.Height;
  230. secondHand.RenderTransform = secondHandRotate;
  231. //Set Initial Position of Hand
  232. Canvas.SetTop(secondHand, centerPoint.Y - handLength);
  233. Canvas.SetLeft(secondHand, WIDTH/2);
  234. ClockArea.Children.Add(secondHand);
  235. }
  236. public void DrawMinuteHand()
  237. {
  238. double handLength = (HEIGHT / 2) - 50;
  239. minuteHand = new Rectangle()
  240. {
  241. Width = 4,
  242. Height = handLength,
  243. Stroke = new SolidColorBrush(Colors.Black),
  244. Fill = new SolidColorBrush(Colors.Black),
  245. HorizontalAlignment = HorizontalAlignment.Center,
  246. VerticalAlignment = VerticalAlignment.Center
  247. };
  248. minuteHand.SetValue(Grid.RowProperty, 0);
  249. minuteHand.SetValue(Grid.ColumnProperty, 0);
  250. minuteHandRotate = new RotateTransform();
  251. minuteHandRotate.Angle = 0;
  252. minuteHandRotate.CenterX = Canvas.GetLeft(minuteHand);
  253. minuteHandRotate.CenterY = minuteHand.Height;
  254. minuteHand.RenderTransform = minuteHandRotate;
  255. Canvas.SetTop(minuteHand, centerPoint.Y - handLength);
  256. Canvas.SetLeft(minuteHand, WIDTH / 2);
  257. ClockArea.Children.Add(minuteHand);
  258. }
  259. public void DrawHourHand()
  260. {
  261. double handLength = (HEIGHT / 2) - 80;
  262. hourHand = new Rectangle()
  263. {
  264. Width = 4,
  265. Height = handLength,
  266. Stroke = new SolidColorBrush(Colors.Black),
  267. Fill = new SolidColorBrush(Colors.Black),
  268. HorizontalAlignment = HorizontalAlignment.Center,
  269. VerticalAlignment = VerticalAlignment.Center
  270. };
  271. hourHand.SetValue(Grid.RowProperty, 0);
  272. hourHand.SetValue(Grid.ColumnProperty, 0);
  273. hourHandRotate = new RotateTransform();
  274. hourHandRotate.Angle = 0;
  275. hourHandRotate.CenterX = Canvas.GetLeft(hourHand);
  276. hourHandRotate.CenterY = hourHand.Height;
  277. hourHand.RenderTransform = hourHandRotate;
  278. Canvas.SetTop(hourHand, centerPoint.Y - handLength);
  279. Canvas.SetLeft(hourHand, WIDTH / 2);
  280. ClockArea.Children.Add(hourHand);
  281. }
  282. }
  283. }
Output

Now execute and you will get a fully drawn Analog Clock.