码迷,mamicode.com
首页 > 其他好文 > 详细

滚轮缩放效果

时间:2014-05-26 20:14:24      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:style   c   class   blog   code   java   

bubuko.com,布布扣
        public void MouseWheelEventHandler(object sender, MouseWheelEventArgs e)
        {
            double oldScalX = ((ScaleTransform)canvas.RenderTransform).ScaleX;
            double oldScalY = ((ScaleTransform)canvas.RenderTransform).ScaleY;

            var storyBoard = new Storyboard();
            //var group = new TransformGroup();
            //var scale = new ScaleTransform(1.5, 1.5);
            //group.Children.Add(scale);
            //group.Children.Add(new TranslateTransform(300, 300));
            //canvas.RenderTransform = group;

            RegisterName("MainCanvas", canvas);

            var growAnimation = new DoubleAnimation();
            QuinticEase ee = new QuinticEase();
            ee.EasingMode = EasingMode.EaseOut;
            growAnimation.EasingFunction = ee;

            growAnimation.From = oldScalX;
            if (e.Delta > 0)
            {
                growAnimation.To = oldScalX + 0.2;
            }
            else
            {
                growAnimation.To = oldScalX - 0.2;
            }
            storyBoard.Children.Add(growAnimation);

            var growAnimation2 = new DoubleAnimation();
            QuinticEase ee2 = new QuinticEase();
            ee2.EasingMode = EasingMode.EaseOut;
            growAnimation2.EasingFunction = ee2;
            growAnimation2.From = oldScalY;
            if (e.Delta > 0)
            {
                growAnimation2.To = oldScalY + 0.2;
            }
            else
            {
                growAnimation2.To = oldScalY - 0.2;
            }
            storyBoard.Children.Add(growAnimation2);


            Storyboard.SetTargetProperty(growAnimation, new PropertyPath("RenderTransform.ScaleX"));
            Storyboard.SetTargetProperty(growAnimation2, new PropertyPath("RenderTransform.ScaleY"));
            Storyboard.SetTargetName(growAnimation, "MainCanvas");
            Storyboard.SetTargetName(growAnimation2, "MainCanvas");
            storyBoard.Begin(this);


        }
bubuko.com,布布扣

添加事件代码

        private void UserControl_Loaded_1(object sender, RoutedEventArgs e)
        {
            Window.GetWindow(this).MouseWheel += MouseWheelEventHandler;
        }

 

滚轮缩放效果,布布扣,bubuko.com

滚轮缩放效果

标签:style   c   class   blog   code   java   

原文地址:http://www.cnblogs.com/wangjixianyun/p/3751778.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!