private void HandleSquishingWhileDragging(double newTranslation) { double translationOfLastItem = -1 * CalculateElementOffset(GetElementCount() - 1); double squishDistance = 0; if (newTranslation > 0) { // We're squishing the first item // squishDistance = newTranslation; _dragState.UnsquishTranslationAnimationTarget = 0; _mediaStrip.RenderTransformOrigin = new Point(0, 0); } else if (newTranslation < translationOfLastItem) { // We're squishing the last item // squishDistance = translationOfLastItem - newTranslation; _dragState.UnsquishTranslationAnimationTarget = translationOfLastItem; _mediaStrip.RenderTransformOrigin = new Point(1, 0); } double squishScale = 1.0 - (squishDistance / _maxDraggingSquishDistance) * (1 - _minDraggingSquishScale); // Apply the squish // _mediaStripCompositeTransform.ScaleX = squishScale; // Update our state // _state = squishScale == 1.0 ? MediaViewerState.Dragging : MediaViewerState.DraggingAndSquishing; }
/// <summary> /// Initializes virtualization if all of the prerequisites are available, so it's safe to call once each is set. /// </summary> private void InitializeVirtualizationIfReady() { if ((_mediaStrip == null) || (_size == null)) { // We don't have everything we need to initialize, wait for the next call return; } // // Initialize the virtualized item pool // _virtualizedItemPool = new List<VirtualizedItem>(); _mediaStrip.Children.Clear(); for (int index = 0; index < _virtualizedItemPoolSize; index++) { VirtualizedItem virtualizedItem = new VirtualizedItem(new Size(_size.Value.Width, _size.Value.Height)); virtualizedItem.DataTemplate = ItemTemplate; virtualizedItem.ItemZoomed += OnItemZoomed; virtualizedItem.ItemUnzoomed += OnItemUnzoomed; _mediaStrip.Children.Add(virtualizedItem.RootFrameworkElement); _virtualizedItemPool.Add(virtualizedItem); } if (_state == MediaViewerState.Uninitialized) { _state = MediaViewerState.Initialized; } ResetDisplayedElement(); ResetItemLayout(); }
private void CompleteDragInertiaAnimation() { if (_dragInertiaAnimation != null) { if (_state == MediaViewerState.InertiaAnimating) { _state = MediaViewerState.Initialized; } ScrollOffset = _dragInertiaAnimationTranslation.To.Value; _dragInertiaAnimation.Stop(); _dragInertiaAnimation = null; _dragInertiaAnimationTranslation = null; UpdateDisplayedElement(_dragState.NewDisplayedElementIndex); } }
private void DragStartedEventHandler() { //Tracing.Trace("DragStartedEventHandler() MediaStripOffset = " + offsetHelper.MediaStripOffset); int elementCount = GetElementCount(); _state = MediaViewerState.Dragging; _dragState.LastDragUpdateTime = DateTime.Now; _dragState.DragStartingMediaStripOffset = ScrollOffset; _dragState.NetDragDistanceSincleLastDragStagnation = 0.0; _dragState.IsDraggingFirstElement = _displayedElementIndex == 0; _dragState.IsDraggingLastElement = _displayedElementIndex == elementCount - 1; _dragState.GotDragDelta = false; }
private void AnimateToElement(int elementIndex, TimeSpan animationDuration) { double animationEndingValue = -1 * CalculateElementOffset(elementIndex); ConstructDragInertiaAnimation(animationEndingValue, animationDuration); _state = MediaViewerState.InertiaAnimating; _dragInertiaAnimation.Begin(); _dragState.NewDisplayedElementIndex = elementIndex; }
protected override void OnManipulationDelta(ManipulationDeltaEventArgs e) { base.OnManipulationDelta(e); if (e.PinchManipulation == null) { if (!IsZoomedInToItem() && (_state == MediaViewerState.Initialized) && (DragEnabled) && (GetElementCount() > 0)) { _state = MediaViewerState.Dragging; DragStartedEventHandler(); } if ((_state == MediaViewerState.Dragging) || (_state == MediaViewerState.DraggingAndSquishing)) { DragDeltaEventHandler(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y); } } }
private void UnsquishAnimationComplete(object sender, EventArgs e) { if (_state == MediaViewerState.UnsquishAnimating) { _state = MediaViewerState.Initialized; } ScrollOffset = _unsquishAnimationTranslation.To.Value; _unsquishAnimation.Stop(); _unsquishAnimation = null; _unsquishAnimationTranslation = null; }
private void StartUndoSquishAnimation() { // Build animation to undo squish // _unsquishAnimation = new Storyboard(); DoubleAnimation scaleAnimation = new DoubleAnimation(); _unsquishAnimationTranslation = new DoubleAnimation(); Storyboard.SetTarget(scaleAnimation, _mediaStripCompositeTransform); Storyboard.SetTarget(_unsquishAnimationTranslation, _mediaStripCompositeTransform); Storyboard.SetTargetProperty(scaleAnimation, new PropertyPath(CompositeTransform.ScaleXProperty)); Storyboard.SetTargetProperty(_unsquishAnimationTranslation, new PropertyPath(CompositeTransform.TranslateXProperty)); scaleAnimation.From = _mediaStripCompositeTransform.ScaleX; _unsquishAnimationTranslation.From = _mediaStripCompositeTransform.TranslateX; scaleAnimation.To = 1.0; _unsquishAnimationTranslation.To = _dragState.UnsquishTranslationAnimationTarget; scaleAnimation.Duration = new TimeSpan(0, 0, 0, 0, _unsquishAnimationMilliseconds); _unsquishAnimationTranslation.Duration = scaleAnimation.Duration; _unsquishAnimation.Children.Add(scaleAnimation); _unsquishAnimation.Children.Add(_unsquishAnimationTranslation); _unsquishAnimation.FillBehavior = FillBehavior.Stop; _unsquishAnimation.Completed += UnsquishAnimationComplete; _state = MediaViewerState.UnsquishAnimating; _unsquishAnimation.Begin(); // Go ahead and set the values we're animating to their final values so when the storyboard ends, these will take effect // _mediaStripCompositeTransform.ScaleX = scaleAnimation.To.Value; _mediaStripCompositeTransform.TranslateX = _unsquishAnimationTranslation.To.Value; }
private void StartDragInertiaAnimation() { TimeSpan lastDragTimeDelta = DateTime.Now - _dragState.LastDragUpdateTime; // Build animation to finish the drag // int elementIndexDelta = CalculateDragInertiaAnimationEndingValue(); TimeSpan animationDuration = CalculateDragInertiaAnimationDuration(lastDragTimeDelta); AnimateToElement(_displayedElementIndex.Value + elementIndexDelta, animationDuration); _state = MediaViewerState.InertiaAnimating; }