Skip to content

Instantly share code, notes, and snippets.

@tmacharia
Created November 24, 2019 20:36
Show Gist options
  • Save tmacharia/5eb66ab9605a0ed0e401997da7cda788 to your computer and use it in GitHub Desktop.
Save tmacharia/5eb66ab9605a0ed0e401997da7cda788 to your computer and use it in GitHub Desktop.
using System;
using Windows.Xaml;
namespace uwp.clock.backend
{
public sealed partial class UwpClockPage : Page
{
private readonly DispatcherTimer _timer;
private double PreviousAngle = 0;
public UwpClockPage()
{
this.InitializeComponent();
_timer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(1)
};
_timer.Tick += (s,e) => OnTick();
}
private void OnTick()
{
// calculate angle of rotation based on current system time seconds.
double angle = DateTime.Now.TimeOfDay.Seconds * 360 / 60;
lock (SpinSecHandStoryBoard)
{
SpinSecHandAnim.From = PreviousAngle;
SpinSecHandAnim.To = angle;
SpinSecHandAnim.Duration = new Duration(TimeSpan.FromSeconds(1));
SpinSecHandStoryBoard.Begin();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment