首页 > 代码库 > 滚轮缩放效果
滚轮缩放效果
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; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。