public static void CloseViewRectAnimation(Grid gSlideBox) { if ((gSlideBox.FindName("zcGrid") as ZoomableCanvas).Children.Count != 0) { Border obj = gSlideBox.FindName("bGridBox") as Border; Thickness margin = obj.Margin; obj.ApplyAnimationClock(FrameworkElement.MarginProperty, null); obj.Margin = margin; } }
public static void UpdateViewRect(Grid gSlideBox, bool bScaleChanged, bool animate = false, float fDurationTime = 0f, EasingFunctionBase easing = null) { MultiScaleImage mSlide = gSlideBox.FindName("mMultiScaleImage") as MultiScaleImage; ZoomableCanvas zcCycleGrid = gSlideBox.FindName("zcGrid") as ZoomableCanvas; Border border = gSlideBox.FindName("bGridBox") as Border; float fTargetScale = mSlide.fTargetScale; if (zcCycleGrid.Children.Count == 0) { return; } System.Windows.Point point = mSlide.SlideRatioToBoxPixel(new System.Windows.Point(0.0, 0.0)); int elementActualAngle = PublicMethods.GetElementActualAngle(mSlide); if (!animate) { zcCycleGrid.ApplyAnimationClock(ZoomableCanvas.ScaleProperty, null); border.ApplyAnimationClock(FrameworkElement.MarginProperty, null); border.Margin = new Thickness(point.X, point.Y, 0.0, 0.0); zcCycleGrid.Scale = fTargetScale; if (bScaleChanged) { foreach (System.Windows.Shapes.Rectangle child in zcCycleGrid.Children) { child.StrokeThickness = 1f / fTargetScale; } } } else { border.BeginAnimation(FrameworkElement.MarginProperty, new ThicknessAnimation(new Thickness(point.X, point.Y, 0.0, 0.0), TimeSpan.FromMilliseconds(fDurationTime)) { EasingFunction = easing }, HandoffBehavior.Compose); if (bScaleChanged) { DoubleAnimation doubleAnimation = new DoubleAnimation(fTargetScale, TimeSpan.FromMilliseconds(fDurationTime)) { EasingFunction = easing }; int i = 0; doubleAnimation.CurrentTimeInvalidated += delegate { Task.Factory.StartNew(delegate { i++; if (i % 3 == 0) { float fCurrentScale = 0f; zcCycleGrid.Dispatcher.BeginInvoke((Action) delegate { fCurrentScale = mSlide.GetCurrentScale(); foreach (System.Windows.Shapes.Rectangle child2 in zcCycleGrid.Children) { child2.StrokeThickness = 1f / fCurrentScale; } }, DispatcherPriority.Loaded); } }, TaskCreationOptions.AttachedToParent); }; zcCycleGrid.BeginAnimation(ZoomableCanvas.ScaleProperty, doubleAnimation, HandoffBehavior.Compose); } } System.Windows.Point point3 = border.RenderTransformOrigin = new System.Windows.Point(0.0, 0.0); border.RenderTransform = new RotateTransform(elementActualAngle); }