private async void OnContentManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) { if ((e.Cumulative.Translation.X > 0 && e.Cumulative.Translation.X >= 150) || (e.Cumulative.Translation.X < 0 && Math.Abs(e.Cumulative.Translation.X) >= this.rightContent.ActualWidth)) { if (e.Cumulative.Translation.X > 0) { await this.FadeOutControlDirection(AnimationDirection.Right); if (this.LeftCommand != null && this.LeftCommand.CanExecute(null)) { this.LeftCommand.Execute(this.DataContext); } await this.FadeOutControl(0); } else if (e.Cumulative.Translation.X < 0) { lastActionListItemAnimated = this; if (this.scrollviewer == null) { this.scrollviewer = TreeHelper.FindVisualAncestor <ScrollViewer>(this); this.scrollviewer.ViewChanging += this.OnScrollViewerViewChanging; } } } else { await this.FadeOutControl(0d); this.leftContent.Visibility = Visibility.Collapsed; this.rightContent.Visibility = Visibility.Collapsed; } }
private Task FadeOutControl(double target) { TimeSpan duration = TimeSpan.FromMilliseconds(200); DoubleAnimationUsingKeyFrames doubleAnimationKeyFrames = new DoubleAnimationUsingKeyFrames(); if (this.content.RenderTransform is CompositeTransform) { doubleAnimationKeyFrames.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = ((CompositeTransform)this.content.RenderTransform).TranslateX }); } doubleAnimationKeyFrames.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = duration, Value = target, EasingFunction = new CubicEase { EasingMode = EasingMode.EaseIn } }); Storyboard.SetTarget(doubleAnimationKeyFrames, this.content); Storyboard.SetTargetProperty(doubleAnimationKeyFrames, "(UIElement.RenderTransform).(CompositeTransform.TranslateX)"); TaskCompletionSource <bool> source = new TaskCompletionSource <bool>(); Storyboard storyBoard = new Storyboard { Duration = duration }; storyBoard.Children.Add(doubleAnimationKeyFrames); storyBoard.Completed += (s, e) => source.SetResult(true); storyBoard.Begin(); lastActionListItemAnimated = null; return(source.Task); }
private void OnContentManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) { if (lastActionListItemAnimated != null) { lastActionListItemAnimated.Reset(); lastActionListItemAnimated = null; } e.Handled = false; var target = e.Cumulative.Translation.X; if (target < 0) { if (this.rightContent.ActualWidth > 0 && Math.Abs(target) > this.rightContent.ActualWidth) { target = this.rightContent.ActualWidth * -1; } } this.leftContent.Visibility = target > 0 ? Visibility.Visible : Visibility.Collapsed; this.rightContent.Visibility = target < 0 ? Visibility.Visible : Visibility.Collapsed; if (this.content.RenderTransform is CompositeTransform) { ((CompositeTransform)this.content.RenderTransform).TranslateX = target; } }