Example #1
0
        private static void Element_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            var element    = sender as FrameworkElement;
            var parent     = element.Parent as FrameworkElement;
            var transforms = (element.RenderTransform as TransformGroup).Children;
            var translate  = transforms.GetTranslate();
            var scale      = transforms.GetScale();

            //ZoomSpeed
            var zoom = e.Delta > 0 ? .2 : -.2;

            var relative = e.GetPosition(element);
            var absolute = e.GetAbsolutePosition(element);
            //必須是scale先,translate後
            var ToScale = Math.Clamp(scale.ScaleX + zoom, GetMaximum(element), 1);
            var ToX     = Math.Clamp(absolute.X - relative.X * ToScale, 0, element.ActualWidth * (1 - ToScale));
            var ToY     = Math.Clamp(absolute.Y - relative.Y * ToScale, 0, element.ActualHeight * (1 - ToScale));

            scale.BeginAnimation(ScaleTransform.ScaleXProperty, ToScale, WheelTime);
            scale.BeginAnimation(ScaleTransform.ScaleYProperty, ToScale, WheelTime);
            translate.BeginAnimation(TranslateTransform.XProperty, ToX, WheelTime);
            translate.BeginAnimation(TranslateTransform.YProperty, ToY, WheelTime);
        }