Esempio n. 1
0
        private async void Weather_ManipulationDelta(object sender, Windows.UI.Xaml.Input.ManipulationDeltaRoutedEventArgs e)
        {
            if (e.IsInertial && !_isSwiped && !_animationRunning)
            {
                var distance = e.Cumulative.Translation.X;
                if (Math.Abs(distance) <= 2)
                {
                    return;
                }

                _isSwiped = true;
                var        translateTransform = CurrentWeatherGrid.RenderTransform = new TranslateTransform();
                Storyboard storyboard         = new Storyboard();

                DoubleAnimationUsingKeyFrames animationKeyFrames = new DoubleAnimationUsingKeyFrames();

                var keyFrame = new LinearDoubleKeyFrame();
                keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(750));
                keyFrame.Value   = distance > 0 ? ActualWidth : -ActualWidth;
                animationKeyFrames.KeyFrames.Add(keyFrame);

                keyFrame         = new LinearDoubleKeyFrame();
                keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(751));
                keyFrame.Value   = distance > 0 ? -ActualWidth : ActualWidth;
                animationKeyFrames.KeyFrames.Add(keyFrame);

                keyFrame         = new LinearDoubleKeyFrame();
                keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(1500));
                keyFrame.Value   = 0;
                animationKeyFrames.KeyFrames.Add(keyFrame);

                Storyboard.SetTargetProperty(animationKeyFrames, "X");
                Storyboard.SetTarget(animationKeyFrames, translateTransform);
                storyboard.Children.Add(animationKeyFrames);

                storyboard.Completed += Animation_Completed;
                _animationRunning     = true;
                storyboard.Begin();

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    await Task.Delay(751);
                    if (distance > 0)
                    {
                        _viewModel.SwitchDay(false);
                    }
                    else
                    {
                        _viewModel.SwitchDay(true);
                    }
                });
            }
        }