private void _invalidateMarkerPosition(bool animate) { var selected = ItemContainerGenerator.ContainerFromItem(SelectedItem) as NavigatorItem; var shouldShowMarker = (selected != null) && (_partMarker != null) && (selected.IsLoaded) && (_partMarker.IsLoaded); var shouldAnimateMarker = shouldShowMarker && animate && _partMarker.Visibility == Visibility.Visible; // special case - selected is not loaded yet. in this case we sign up to the loaded event and re do this if ((selected != null) && (!selected.IsLoaded)) { selected.Loaded += (s, e) => _invalidateMarkerPosition(animate); return; } var duration = shouldAnimateMarker ? Duration : new Duration(TimeSpan.Zero); if (shouldShowMarker) { _partMarker.Visibility = Visibility.Visible; var matrix = _calcTransformationToTarget(selected); _animateMarkerTo(matrix, selected.ActualWidth, selected.ActualHeight, duration); } else { if (_partMarker != null) { _partMarker.Visibility = Visibility.Hidden; _partMarker.BeginAnimation(WidthProperty, null); _partMarker.BeginAnimation(HeightProperty, null); _markerTransform.BeginAnimation(MatrixTransform.MatrixProperty, null); } } }
// currently not in use... private void AnimatePutCard2(int iLocationIndex) { Canvas targetCanves = GetCanvas(iLocationIndex); Point pointCanvasCorner = targetCanves.PointToScreen(new Point(0, 0)); // Create the animation path. PathGeometry animationPath = new PathGeometry(); PathFigure pFigure = new PathFigure(); PolyBezierSegment pBezierSegment = new PolyBezierSegment(); pFigure.StartPoint = new Point(-pointCanvasCorner.X + this.ActualWidth / 2, -pointCanvasCorner.Y); pBezierSegment.Points.Add(pFigure.StartPoint); pBezierSegment.Points.Add(new Point(0, 0)); // Create a MatrixTransform. This transform will be used to move the button. MatrixTransform matrixTransform = new MatrixTransform(); targetCanves.RenderTransform = matrixTransform; pFigure.Segments.Add(pBezierSegment); animationPath.Figures.Add(pFigure); // Freeze the PathGeometry for performance benefits. animationPath.Freeze(); // Create a MatrixAnimationUsingPath to move the // button along the path by animating its MatrixTransform. MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath(); matrixAnimation.PathGeometry = animationPath; matrixAnimation.Duration = TimeSpan.FromSeconds(1); // Set the animation's DoesRotateWithTangent property // to true so that rotates the card in addition to moving it. matrixAnimation.DoesRotateWithTangent = true; matrixAnimation.Completed += delegate { // the cards get reversed - there for need animation to flip it... DoubleAnimation da = new DoubleAnimation(180, 0, TimeSpan.FromSeconds(0.34)); RotateTransform rt = new RotateTransform(0, targetCanves.ActualWidth / 2, targetCanves.ActualHeight / 2);//targetCanves.ActualHeight); targetCanves.RenderTransform = rt; rt.BeginAnimation(RotateTransform.AngleProperty, da); }; matrixTransform.BeginAnimation(MatrixTransform.MatrixProperty, matrixAnimation); }
/// <summary> /// Set element position with or whitout animation /// </summary> /// <param name="toElement">target element to move</param> /// <param name="DoAnimation">do or do not animation</param> /// <param name="animation">To and From value will be setted. If null a default animation will be used</param> public void SetPosition(FrameworkElement toElement, bool DoAnimation = false, MatrixAnimation animation = null) { this.Element.UpdateLayout(); GeneralTransform trans_MovableInFrom_Offset_On_To = toElement.TransformToVisual(this.Element); Matrix reverseMatrix = (trans_MovableInFrom_Offset_On_To as MatrixTransform).Matrix; Transform transform = this.ElementTransform; MatrixTransform mt = Utility.GetMatrixTransformFromTransform(transform); Matrix newMatrix = mt.Matrix; newMatrix.Prepend(reverseMatrix); Matrix oldMatrix = mt.Matrix; MatrixTransform matrixTransform = new MatrixTransform(oldMatrix); if (DoAnimation) { if (animation != null) { animation.From = oldMatrix; animation.To = newMatrix; } else { animation = new MatrixAnimation(oldMatrix, newMatrix, new Duration(new TimeSpan(0, 0, 1))) { EasingFunction = new PowerEase { EasingMode = EasingMode.EaseInOut, Power = 2 } }; } this.ElementTransform = (MatrixTransform)matrixTransform; if (!DoAnimation) { animation.Duration = new Duration(new TimeSpan(0)); } matrixTransform.BeginAnimation(MatrixTransform.MatrixProperty, animation); } else { this.ElementTransform = new MatrixTransform(newMatrix); } }
private void AnimatePutCard(int iLocationIndex) { Canvas targetCanves = GetCanvas(iLocationIndex); Point pointCanvasCorner = targetCanves.PointToScreen(new Point(0, 0)); Point pointWindowCorner = PointToScreen(new Point(0, 0)); // Create the animation path. PathGeometry animationPath = new PathGeometry(); PathFigure pFigure = new PathFigure(); PolyLineSegment pLineSegment = new PolyLineSegment(); Point pointStart = new Point(); pointStart.X = pointWindowCorner.X - pointCanvasCorner.X + this.ActualWidth / 2 - targetCanves.ActualHeight / 4; pointStart.Y = pointWindowCorner.Y - pointCanvasCorner.Y - targetCanves.ActualWidth; pFigure.StartPoint = pointStart; pLineSegment.Points.Add(pFigure.StartPoint); pLineSegment.Points.Add(new Point(0, 0)); // Create a MatrixTransform. This transform will be used to move the button. MatrixTransform matrixTransform = new MatrixTransform(); targetCanves.RenderTransform = matrixTransform; pFigure.Segments.Add(pLineSegment); animationPath.Figures.Add(pFigure); // Freeze the PathGeometry for performance benefits. animationPath.Freeze(); // Create a MatrixAnimationUsingPath to move the // button along the path by animating its MatrixTransform. MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath(); matrixAnimation.PathGeometry = animationPath; matrixAnimation.Duration = TimeSpan.FromSeconds(iAnimationPutCardTime); DoubleAnimation doubleAnimation = new DoubleAnimation(90, 360, TimeSpan.FromSeconds(iAnimationPutCardTime)); RotateTransform renderTransform = new RotateTransform(0, targetCanves.ActualWidth / 2, targetCanves.ActualHeight / 2);//targetCanves.ActualHeight); targetCanves.Children[0].RenderTransform = renderTransform; renderTransform.BeginAnimation(RotateTransform.AngleProperty, doubleAnimation); //matrixAnimation.DoesRotateWithTangent = true; matrixTransform.BeginAnimation(MatrixTransform.MatrixProperty, matrixAnimation); }
/// <summary> /// Reset element transform. Set actual transform to Origin transform /// </summary> public void ResetTransform() { MatrixTransform mt = Utility.GetMatrixTransformFromTransform(this.ElementTransform); Matrix oldMatrix = mt.Matrix; Matrix newMatrix = Utility.GetMatrixTransformFromTransform(OriginalElementTransform).Matrix; MatrixAnimation matrixAnimation = new MatrixAnimation(oldMatrix, newMatrix, new Duration(new TimeSpan(0, 0, 1))) { EasingFunction = new PowerEase { EasingMode = EasingMode.EaseInOut, Power = 2 } }; MatrixTransform matrixTransform = new MatrixTransform(oldMatrix); this.ElementTransform = (MatrixTransform)matrixTransform; matrixTransform.BeginAnimation(MatrixTransform.MatrixProperty, matrixAnimation); }
private void AnimatePutCardMiddleOrRight(int iLocationIndex) { Canvas targetCanves = GetCanvas(iLocationIndex); Point pointCanvasCorner = targetCanves.PointToScreen(new Point(0, 0)); // Create the animation path. PathGeometry animationPath = new PathGeometry(); PathFigure pFigure = new PathFigure(); PolyBezierSegment pBezierSegment = new PolyBezierSegment(); pFigure.StartPoint = new Point(-pointCanvasCorner.X + this.ActualWidth / 2, -pointCanvasCorner.Y); pBezierSegment.Points.Add(pFigure.StartPoint); pBezierSegment.Points.Add(new Point(-targetCanves.ActualWidth, 0)); pBezierSegment.Points.Add(new Point(0, 0)); // Create a MatrixTransform. This transform will be used to move the button. MatrixTransform matrixTransform = new MatrixTransform(); targetCanves.RenderTransform = matrixTransform; pFigure.Segments.Add(pBezierSegment); animationPath.Figures.Add(pFigure); // Freeze the PathGeometry for performance benefits. animationPath.Freeze(); // Create a MatrixAnimationUsingPath to move the // button along the path by animating its MatrixTransform. MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath(); matrixAnimation.PathGeometry = animationPath; matrixAnimation.Duration = TimeSpan.FromSeconds(iAnimationPutCardTime); // Set the animation's DoesRotateWithTangent property // to true so that rotates the card in addition to moving it. matrixAnimation.DoesRotateWithTangent = true; matrixTransform.BeginAnimation(MatrixTransform.MatrixProperty, matrixAnimation); }
private void AnimateMoveCard(int iLocationFrom, int iLocationTo) { Canvas canvesFrom = GetCanvas(iLocationFrom); Point pointCanvasCornerFrom = canvesFrom.PointToScreen(new Point(0, 0)); Canvas canvesTo = GetCanvas(iLocationTo); Point pointCanvasCornerTo = canvesTo.PointToScreen(new Point(0, 0)); // Create the animation path. PathGeometry animationPath = new PathGeometry(); PathFigure pFigure = new PathFigure(); PolyLineSegment pLineSegment = new PolyLineSegment(); pFigure.StartPoint = new Point(0, 0); pLineSegment.Points.Add(pFigure.StartPoint); pLineSegment.Points.Add(new Point(pointCanvasCornerTo.X - pointCanvasCornerFrom.X, pointCanvasCornerTo.Y - pointCanvasCornerFrom.Y)); // Create a MatrixTransform. This transform will be used to move the button. MatrixTransform matrixTransform = new MatrixTransform(); pFigure.Segments.Add(pLineSegment); animationPath.Figures.Add(pFigure); // Freeze the PathGeometry for performance benefits. animationPath.Freeze(); // Create a MatrixAnimationUsingPath to move the // button along the path by animating its MatrixTransform. MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath(); matrixAnimation.PathGeometry = animationPath; matrixAnimation.Duration = TimeSpan.FromSeconds(iAnimationRemoveCardTime); canvesFrom.Children[0].RenderTransform = matrixTransform; matrixAnimation.Completed += delegate { MoveCard(iLocationFrom, iLocationTo); }; matrixTransform.BeginAnimation(MatrixTransform.MatrixProperty, matrixAnimation); }