private void UpdateNextItem()
{
var sb = new Windows.UI.Xaml.Media.Animation.Storyboard();
if (_translate != null)
{
var anim = new Windows.UI.Xaml.Media.Animation.DoubleAnimation();
anim.Duration = new Duration(TimeSpan.FromMilliseconds(500));
anim.From = 0;
if(Direction == LiveTile.SlideDirection.Up)
anim.To = -this.ActualHeight;
else if (Direction == LiveTile.SlideDirection.Left)
anim.To = -this.ActualWidth;
anim.FillBehavior = Windows.UI.Xaml.Media.Animation.FillBehavior.HoldEnd;
anim.EasingFunction = new Windows.UI.Xaml.Media.Animation.CubicEase() { EasingMode = Windows.UI.Xaml.Media.Animation.EasingMode.EaseOut };
Windows.UI.Xaml.Media.Animation.Storyboard.SetTarget(anim, _translate);
if(Direction == LiveTile.SlideDirection.Up
// || this.SlideDirection == SlideView.SlideDirection.Down
)
Windows.UI.Xaml.Media.Animation.Storyboard.SetTargetProperty(anim, "Y");
else
Windows.UI.Xaml.Media.Animation.Storyboard.SetTargetProperty(anim, "X");
sb.Children.Add(anim);
}
sb.Completed += (a, b) =>
{
//Reset back and swap images, getting the next image ready
if (_currentElement != null)
_currentElement.DataContext = GetCurrent();
DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(250) }; //Give the next panel a little time to load
timer.Tick += (s, e) =>
{
timer.Stop();
sb.Stop(); //Also resets transform
if (_nextElement != null)
_nextElement.DataContext = GetNext();
};
timer.Start();
};
sb.Begin();
}