zoukankan      html  css  js  c++  java
  • 滚轮缩放效果

            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);
    
    
            }

    添加事件代码

            private void UserControl_Loaded_1(object sender, RoutedEventArgs e)
            {
                Window.GetWindow(this).MouseWheel += MouseWheelEventHandler;
            }
  • 相关阅读:
    IIS7用进程池的PID查找占用CPU的站点
    CSS中属性的书写顺序
    int[] 和 string[] 互换
    csv 文件的读取
    扩展 DataGridView 的功能(三)
    [音乐] the dream catcher
    雷人的面试
    将MP3文件嵌入到exe中并播放
    扩展 DataGridView 的功能(二)
    扩展DataGridView 的功能(四)
  • 原文地址:https://www.cnblogs.com/wangjixianyun/p/3751778.html
Copyright © 2011-2022 走看看