Today I was in the process of making my own copy-paste Analog clock. I went aruond the internet and found this pretty thing. Of course I could have used that code and gone on with life. But that was not the point of the exercise. I wanted to learn something of this.
I liked the way he did the animations, no more need for a timer to update the angles, all is done in XAML.
So his project is Silverlight. And he has this to aniamte the hands of the clock.
<DoubleAnimation From="0" To="360" Duration="00:01:00" RepeatBehavior="Forever"
and this in his codebehind
private void SecondsHandCanvas_Loaded( object sender, RoutedEventArgs e )
this.SecondsHandStoryboard.Seek( DateTime.Now.TimeOfDay );
Private Sub SecondsHandCanvas_Loaded( ByVal sender As object, ByVal e As RoutedEventArgs)
Me.SecondsHandStoryboard.Seek( DateTime.Now.TimeOfDay );
Cool I can just copy paste that and get on with it.
But Silverlight and WPF aren’t exactly the same they just look the same.
In WPF A name is no good for a resource apparently. It needs a Key.
So the above XAML becomes this instead of the above Silverlight code.
<DoubleAnimation From="0" To="360" Duration="12:00:00" RepeatBehavior="Forever" Storyboard.TargetProperty="(Polygon.RenderTransform).(RotateTransform.Angle)" Storyboard.TargetName="HourHand"/>
And then you find out that the code you have doesn’t work either. YOu need to change it to this.
Private Sub HoursHandCanvas_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Dim s = CType(Me.HoursHandCanvas.Resources("SecondHandStoryboard"), Storyboard)
private void HoursHandCanvas_Loaded(System.Object, sender,System.Windows.RoutedEventArgs e)
var s = (StoryBoard)this.HoursHandCanvas.Resources("SecondHandStoryboard");
And BTW doing s.Begin(Me, True) does not work whatever MSDN say.