Ejemplo n.º 1
0
        /// <summary>
        /// 对inkcanvas进行缩放并旋转
        /// </summary>
        /// <param name="inkcanvas">缩放对象</param>
        /// <param name="rate">缩放比率</param>
        public static void InkCanvasZoomRotate(InkCanvas inkCanvas, double duration, double fromZoomRate, double toZoomRate, double centerX, double centerY)
        {
            TransformGroup transformGroup = new TransformGroup();
            ScaleTransform scaleTransform = new ScaleTransform();

            transformGroup.Children.Add(scaleTransform);
            //inkCanvas.RenderTransform = scaleTransform;
            scaleTransform.CenterX = inkCanvas.ActualWidth * centerX;
            scaleTransform.CenterY = inkCanvas.ActualHeight * centerY;
            DoubleAnimation myDoubleAnimation = new DoubleAnimation();

            //宽度缩放
            myDoubleAnimation.From     = fromZoomRate;
            myDoubleAnimation.To       = toZoomRate;
            myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(duration));
            if (inkCanvas.FindName("scaleTransform") != null)
            {
                inkCanvas.UnregisterName("scaleTransform");
            }
            inkCanvas.RegisterName("scaleTransform", scaleTransform);
            Storyboard.SetTargetName(myDoubleAnimation, "scaleTransform");
            Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(ScaleTransform.ScaleXProperty));


            DoubleAnimation myDoubleAnimationHeight = new DoubleAnimation();

            //高度缩放
            myDoubleAnimationHeight.From     = fromZoomRate;
            myDoubleAnimationHeight.To       = toZoomRate;
            myDoubleAnimationHeight.Duration = myDoubleAnimation.Duration;
            Storyboard.SetTargetName(myDoubleAnimationHeight, "scaleTransform");
            Storyboard.SetTargetProperty(myDoubleAnimationHeight, new PropertyPath(ScaleTransform.ScaleYProperty));

            RotateTransform rotateTransform = new RotateTransform();

            transformGroup.Children.Add(rotateTransform);
            inkCanvas.RenderTransform = transformGroup;
            rotateTransform.CenterX   = scaleTransform.CenterX;
            rotateTransform.CenterY   = scaleTransform.CenterY;
            DoubleAnimation rotateDoubleAnimation = new DoubleAnimation();

            rotateDoubleAnimation.From     = 0;
            rotateDoubleAnimation.To       = 720;
            rotateDoubleAnimation.Duration = myDoubleAnimation.Duration;
            if (inkCanvas.FindName("rotateTransform") != null)
            {
                inkCanvas.UnregisterName("rotateTransform");
            }
            inkCanvas.RegisterName("rotateTransform", rotateTransform);
            Storyboard.SetTargetName(rotateDoubleAnimation, "rotateTransform");
            Storyboard.SetTargetProperty(rotateDoubleAnimation, new PropertyPath(RotateTransform.AngleProperty));


            Storyboard myStoryboard = new Storyboard();

            myStoryboard.Children.Add(myDoubleAnimation);
            myStoryboard.Children.Add(myDoubleAnimationHeight);
            myStoryboard.Children.Add(rotateDoubleAnimation);
            myStoryboard.Begin(inkCanvas);
        }
Ejemplo n.º 2
0
        public void moveStoryBoard(int index, double startLeft, double endLeft, int currIndex)
        {
            var tg              = new TransformGroup();
            var translation     = new TranslateTransform();
            var translationName = "myTranslation" + translation.GetHashCode();

            InkCanvas.RegisterName(translationName, translation);
            tg.Children.Add(translation);
            keyFrames[index].Image.RenderTransform = tg;
            DoubleAnimation myDoubleAnimation = new DoubleAnimation();

            myDoubleAnimation.From     = startLeft;// keyFrames[index].Image.Margin.Left;
            myDoubleAnimation.To       = endLeft;
            myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(MoveTime));

            var s = new Storyboard();

            Storyboard.SetTargetName(s, translationName);
            Storyboard.SetTargetProperty(s, new PropertyPath(TranslateTransform.XProperty));
            var storyboardName = "s" + s.GetHashCode();

            s.Children.Add(myDoubleAnimation);
            s.Begin(InkCanvas);

            //摘要左边距动画
            if (index == currIndex)
            {
                var tgInkcanvas              = new TransformGroup();
                var translationInkcanvas     = new TranslateTransform();
                var translationNameInkcanvas = "myTranslationInkcanvas" + translationInkcanvas.GetHashCode();
                parentInkcanvas.RegisterName(translationNameInkcanvas, translationInkcanvas);
                tgInkcanvas.Children.Add(translationInkcanvas);
                InkCanvas.RenderTransform = tgInkcanvas;
                DoubleAnimation myDoubleAnimationInkcanvas = new DoubleAnimation();
                myDoubleAnimationInkcanvas.From = 0;
                InkCanvasOffsetX = startLeft - endLeft;
                //InkCanvasOffsetX = ((startLeft==360||startLeft==240)&&InkCanvasOffsetX > 0 ? 0 : InkCanvasOffsetX);
                myDoubleAnimationInkcanvas.To = InkCanvasOffsetX;

                myDoubleAnimationInkcanvas.Duration = new Duration(TimeSpan.FromSeconds(MoveTime));
                Storyboard.SetTargetName(myDoubleAnimationInkcanvas, translationNameInkcanvas);
                Storyboard.SetTargetProperty(myDoubleAnimationInkcanvas, new PropertyPath(TranslateTransform.XProperty));
                var sInkcanvas = new Storyboard();
                var storyboardNameInkcanvas = "s" + s.GetHashCode();
                sInkcanvas.Children.Add(myDoubleAnimationInkcanvas);
                sInkcanvas.Completed += new EventHandler(sInkcanvas_Completed);
                sInkcanvas.Begin(parentInkcanvas);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 对inkcanvas进行缩放
        /// </summary>
        /// <param name="inkcanvas">缩放对象</param>
        /// <param name="rate">缩放比率</param>
        public void InkCanvasZoom(InkCanvas inkCanvas, double fromRate, double toRate, double centerX, double centerY)
        {
            //((ScaleTransform)inkCanvas.RenderTransform).CenterX = centerX;
            //((ScaleTransform)inkCanvas.RenderTransform).CenterY = centerY;
            ScaleTransform scaleTransform = new ScaleTransform();

            inkCanvas.RenderTransform = scaleTransform;
            scaleTransform.CenterX    = inkCanvas.ActualWidth * centerX;
            scaleTransform.CenterY    = inkCanvas.ActualHeight * centerY;
            DoubleAnimation myDoubleAnimation = new DoubleAnimation();

            //宽度缩放
            myDoubleAnimation.From     = fromRate;
            myDoubleAnimation.To       = toRate;
            myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.5));
            if (inkCanvas.FindName("scaleTransform") != null)
            {
                inkCanvas.UnregisterName("scaleTransform");
            }
            inkCanvas.RegisterName("scaleTransform", scaleTransform);
            Storyboard.SetTargetName(myDoubleAnimation, "scaleTransform");
            Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(ScaleTransform.ScaleXProperty));


            DoubleAnimation myDoubleAnimationHeight = new DoubleAnimation();

            //高度缩放
            myDoubleAnimationHeight.From     = fromRate;
            myDoubleAnimationHeight.To       = toRate;
            myDoubleAnimationHeight.Duration = new Duration(TimeSpan.FromSeconds(0.5));
            Storyboard.SetTargetName(myDoubleAnimationHeight, "scaleTransform");
            Storyboard.SetTargetProperty(myDoubleAnimationHeight, new PropertyPath(ScaleTransform.ScaleYProperty));


            Storyboard myStoryboard = new Storyboard();

            myStoryboard.Children.Add(myDoubleAnimation);
            myStoryboard.Children.Add(myDoubleAnimationHeight);
            myStoryboard.Begin(inkCanvas);
        }