Here is designer code xaml:

  1. <UserControl x:Class="Clock.Page"
  2. xmlns="http://schemas.microsoft.com/client/2007"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. Width="400" Height="400">
  5. <Canvas Width="400" Height="400" Loaded="Canvas_Loaded">
  6. <Canvas.Resources>
  7. <Storyboard x:Name="clockStoryboard">
  8. <!-- This animation targets the hour hand transform -->
  9. <DoubleAnimation x:Name="hourAnimation"
  10. Storyboard.TargetName="hourHandTransform"
  11. Storyboard.TargetProperty="Angle"
  12. Duration="12:0:0" RepeatBehavior="Forever"/>
  13. <!-- This animation targets the minute hand transform -->
  14. <DoubleAnimation x:Name="minuteAnimation"
  15. Storyboard.TargetName="minuteHandTransform"
  16. Storyboard.TargetProperty="Angle"
  17. Duration="1:0:0" RepeatBehavior="Forever"/>
  18. <!-- This animation targets the second hand transform -->
  19. <DoubleAnimation x:Name="secondAnimation"
  20. Storyboard.TargetName="secondHandTransform"
  21. Storyboard.TargetProperty="Angle"
  22. Duration="0:1:0" RepeatBehavior="Forever"/>
  23. </Storyboard>
  24. </Canvas.Resources>
  25. <!-- Clock Shadow -->
  26. <!--<Ellipse Width="330" Height="330" Canvas.Left="40"
  27. Canvas.Top="40" Fill="Black" Opacity="0.5"/>-->
  28. <!-- Outer rim -->
  29. <Ellipse Stroke="#FF000000" x:Name="outerCircle" Width="330" Height="330"
  30. Canvas.Left="32" Canvas.Top="32">
  31. <Ellipse.Fill>
  32. <!--This linear gradient creates a subtle shadow effect on the outer rim. -->
  33. <LinearGradientBrush EndPoint="0.196,0.127" StartPoint="0.852,0.814">
  34. <GradientStop Color="#FFC0C0C0" Offset="0.788"/>
  35. <GradientStop Color="#FFE4E5F4" Offset="0.995"/>
  36. </LinearGradientBrush>
  37. </Ellipse.Fill>
  38. </Ellipse>
  39. <!-- Bevel -->
  40. <Ellipse Stroke="#FF000000" Width="290" Height="281" Canvas.Left="52"
  41. Canvas.Top="57">
  42. <Ellipse.Fill>
  43. <!-- This linear gradient creates a subtle shadow effect on
  44. the outer rim. -->
  45. <LinearGradientBrush EndPoint="0.867,0.848" StartPoint="0.232,0.126">
  46. <GradientStop Offset="0.1"/>
  47. <GradientStop Color="#FFE4E5F4" Offset="0.995"/>
  48. </LinearGradientBrush>
  49. </Ellipse.Fill>
  50. </Ellipse>
  51. <!-- Clock Face -->
  52. <!--<Ellipse Stroke="#FF000000" Width="273" Height="265"
  53. Canvas.Left="60" Canvas.Top="65" Fill="#FF000000"/>-->
  54. <!-- Central Clock Circle -->
  55. <Ellipse StrokeThickness="7"
  56. Width="32" Height="31" Canvas.Left="180" Canvas.Top="190">
  57. <Ellipse.Stroke>
  58. <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
  59. <GradientStop Color="Black" Offset="0" />
  60. <GradientStop Color="White" Offset="1" />
  61. </LinearGradientBrush>
  62. </Ellipse.Stroke>
  63. <Ellipse.Fill>
  64. <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
  65. <GradientStop Color="Black" Offset="1" />
  66. <GradientStop Color="White" Offset="0" />
  67. </LinearGradientBrush>
  68. </Ellipse.Fill>
  69. </Ellipse>
  70. <!-- Minute Hand -->
  71. <Rectangle Fill="Gray" Width="8" Height="80" Canvas.Left="192.5" Canvas.Top="226"
  72. RenderTransformOrigin="0.41,-0.26" x:Name="MinutedHand">
  73. <Rectangle.RenderTransform>
  74. <RotateTransform x:Name="minuteHandTransform"/>
  75. </Rectangle.RenderTransform>
  76. </Rectangle>
  77. <!-- Hour Hand -->
  78. <Rectangle Fill="Gray" Width="10" Height="60" Canvas.Left="192.5" Canvas.Top="226"
  79. RenderTransformOrigin="0.35,-0.35" x:Name="HourHand">
  80. <Rectangle.RenderTransform>
  81. <RotateTransform x:Name="hourHandTransform"/>
  82. </Rectangle.RenderTransform>
  83. </Rectangle>
  84. <!-- Second Hand -->
  85. <Rectangle Fill="Gray" Width="5" Height="80" Canvas.Left="192.5" Canvas.Top="226"
  86. RenderTransformOrigin="0.65,-0.26" x:Name="SecondHand" >
  87. <Rectangle.RenderTransform>
  88. <RotateTransform x:Name="secondHandTransform"/>
  89. </Rectangle.RenderTransform>
  90. </Rectangle>
  91. </Canvas>
  92. </UserControl>
Now go to view code in C#:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Documents;
  7. using System.Windows.Input;
  8. using System.Windows.Media;
  9. using System.Windows.Media.Animation;
  10. using System.Windows.Shapes;
  11. namespace Clock
  12. {
  13. public partial class Page : UserControl
  14. {
  15. public Page()
  16. {
  17. InitializeComponent();
  18. }
  19. public void Canvas_Loaded(object sender, EventArgs e)
  20. {
  21. // The current date and time.
  22. System.DateTime date = DateTime.Now;
  23. // Find the appropriate angle (in degrees) for the hour hand
  24. // based on the current time.
  25. double hourangle = (((float)date.Hour) / 12) * 360 + date.Minute / 2;
  26. // The transform is already rotated 116.5 degrees to make the hour hand be
  27. // in the 12 o'clock position. You must build this already existing angle
  28. // into the hourangle.
  29. hourangle += 180;
  30. // The same as for the hour angle.
  31. double minangle = (((float)date.Minute) / 60) * 360;
  32. minangle += 180;
  33. // The same for the hour angle.
  34. double secangle = (((float)date.Second) / 60) * 360;
  35. secangle += 180;
  36. // Set the beginning of the animation (From property) to the angle
  37. // corresponging to the current time.
  38. hourAnimation.From = hourangle;
  39. // Set the end of the animation (To property)to the angle
  40. // corresponding to the current time PLUS 360 degrees. Thus, the
  41. // animation will end after the clock hand moves around the clock
  42. // once. Note: The RepeatBehavior property of the animation is set
  43. // to "Forever" so the animation will begin again as soon as it completes.
  44. hourAnimation.To = hourangle + 360;
  45. // Same as with the hour animation.
  46. minuteAnimation.From = minangle;
  47. minuteAnimation.To = minangle + 360;
  48. // Same as with the hour animation.
  49. secondAnimation.From = secangle;
  50. secondAnimation.To = secangle + 360;
  51. // Start the storyboard.
  52. clockStoryboard.Begin();
  53. }
  54. }
  55. }
Canvas and StoryBoard controls are main part of this.

clock

Here is 3D Clock in silverlight with C#.