Hi,
you cam simplified your code:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows.Threading;
namespace Sliding_Watch
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
double[] digits = new double[6];
public MainWindow()
{
InitializeComponent();
DispatcherTimer MyTimer = new DispatcherTimer();
MyTimer.Interval = TimeSpan.FromSeconds(1);
MyTimer.Tick += MyTimer_Tick;
MyTimer.Start();
}
private void ClockAnimation(StackPanel MyPanel, double MyTo)
{
Storyboard MyStory = new Storyboard();
ThicknessAnimation ani = new ThicknessAnimation();
ani.From = MyPanel.Margin;
ani.To = new Thickness(0, MyTo, 0, 0);
ani.Duration = new Duration(TimeSpan.FromMilliseconds(100));
Storyboard.SetTarget(ani, MyPanel);
Storyboard.SetTargetProperty(ani, new PropertyPath("Margin"));
MyStory.Children.Add(ani);
MyStory.Begin();
}
private void MyTimer_Tick(object sender, EventArgs e)
{
double[] newdigits = GetDigits();
if (digits[0] != newdigits[0]) ClockAnimation(StackHours01, -newdigits[0] * 150);
if (digits[1] != newdigits[1]) ClockAnimation(StackHours02, -newdigits[1] * 150);
if (digits[2] != newdigits[2]) ClockAnimation(StackMins01, -newdigits[2] * 150);
if (digits[3] != newdigits[3]) ClockAnimation(StackMins02, -newdigits[3] * 150);
if (digits[4] != newdigits[4]) ClockAnimation(StackSec01, -newdigits[4] * 150);
if (digits[5] != newdigits[5]) ClockAnimation(StackSec02, -newdigits[5] * 150);
digits = newdigits;
}
private double[] GetDigits()
{
double[] d = new double[6];
string t = DateTime.Now.ToString("HHmmss");
for (int i = 0; i < 6; i++) d[i] = int.Parse(t.Substring(i, 1));
return d;
}
private void MainBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
}
}