コード例 #1
0
        private void EditCanvas_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            DesignerBaseCanvas it1 = sender as DesignerBaseCanvas;

            if (it1 == null)
            {
                return;
            }

            if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
            {
                IPagePropertyData page = this.DataContext as IPagePropertyData;
                Rect selectWdgBounding = page.BoundingRect;

                if (e.Delta > 0)
                {
                    //ExternCanvas.
                    ScaleTransform scaletransform = ExternCanvasBorder.RenderTransform as ScaleTransform;

                    scaletransform.ScaleX = PageScaleEnumerator.GetValue(scaletransform.ScaleX, true);// Math.Min(1.7, scaletransform.ScaleX + 0.01);

                    double hOffset = (selectWdgBounding.Left + selectWdgBounding.Width / 2) * scaletransform.ScaleX - DesignerScrollViewer.ActualWidth / 2;
                    double vOffset = (selectWdgBounding.Top + selectWdgBounding.Height / 2) * scaletransform.ScaleX - DesignerScrollViewer.ActualHeight / 2;
                    DesignerScrollViewer.ScrollToHorizontalOffset(hOffset);
                    DesignerScrollViewer.ScrollToVerticalOffset(vOffset);

                    NLogger.Debug("e.Delta: " + e.Delta + " Scale: " + scaletransform.ScaleX + " view width: " + viewWidth + " view height: " + viewHeight + " horizontalOffset: " + hOffset + " verticalOffset:" + vOffset + " DesignerScrollViewer.ActualWidth:" + DesignerScrollViewer.ActualWidth);
                }
                else if (e.Delta < 0)
                {
                    ScaleTransform scaletransform = ExternCanvasBorder.RenderTransform as ScaleTransform;
                    scaletransform.ScaleX = PageScaleEnumerator.GetValue(scaletransform.ScaleX, false); //Math.Max(0.3, scaletransform.ScaleX - 0.01);
                    //scaletransform.ScaleY = PageScaleEnumerator.GetValue(scaletransform.ScaleY, false); //Math.Max(0.3, scaletransform.ScaleY - 0.01);
                    double hOffset = (selectWdgBounding.Left + selectWdgBounding.Width / 2) * scaletransform.ScaleX - DesignerScrollViewer.ActualWidth / 2;
                    double vOffset = (selectWdgBounding.Top + selectWdgBounding.Height / 2) * scaletransform.ScaleX - DesignerScrollViewer.ActualHeight / 2;
                    DesignerScrollViewer.ScrollToHorizontalOffset(hOffset);
                    DesignerScrollViewer.ScrollToVerticalOffset(vOffset);

                    NLogger.Debug("e.Delta: " + e.Delta + " Scale: " + scaletransform.ScaleX + " view width: " + viewWidth + " view height: " + viewHeight + " horizontalOffset: " + hOffset + " verticalOffset:" + vOffset + " DesignerScrollViewer.ActualWidth:" + DesignerScrollViewer.ActualWidth);
                }

                e.Handled = true;
            }
        }
コード例 #2
0
        private void EditCanvas_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            DesignerBaseCanvas it = sender as DesignerBaseCanvas;

            if (it == null)
            {
                return;
            }

            if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
            {
                IPagePropertyData page = this.DataContext as IPagePropertyData;
                Rect selectWdgBounding = page.BoundingRect;

                if (e.Delta > 0)
                {
                    //ExternCanvas.
                    ScaleTransform scaletransform = ExternCanvasBorder.RenderTransform as ScaleTransform;
                    //scaletransform.ScaleX = Math.Min(1.7, scaletransform.ScaleX + 0.01);
                    //scaletransform.ScaleY = Math.Min(1.7, scaletransform.ScaleY + 0.01);
                    scaletransform.ScaleX = PageScaleEnumerator.GetValue(scaletransform.ScaleX, true);

                    DesignerScrollViewer.ScrollToHorizontalOffset((selectWdgBounding.Left + selectWdgBounding.Width / 2) * scaletransform.ScaleX - DesignerScrollViewer.ActualWidth / 2);
                    DesignerScrollViewer.ScrollToVerticalOffset((selectWdgBounding.Top + selectWdgBounding.Height / 2) * scaletransform.ScaleX - DesignerScrollViewer.ActualHeight / 2);
                }
                else if (e.Delta < 0)
                {
                    ScaleTransform scaletransform = ExternCanvasBorder.RenderTransform as ScaleTransform;
                    //scaletransform.ScaleX = Math.Max(0.3, scaletransform.ScaleX - 0.01);
                    //scaletransform.ScaleY = Math.Max(0.3, scaletransform.ScaleY - 0.01);
                    scaletransform.ScaleX = PageScaleEnumerator.GetValue(scaletransform.ScaleX, false);
                    DesignerScrollViewer.ScrollToHorizontalOffset((selectWdgBounding.Left + selectWdgBounding.Width / 2) * scaletransform.ScaleX - DesignerScrollViewer.ActualWidth / 2);
                    DesignerScrollViewer.ScrollToVerticalOffset((selectWdgBounding.Top + selectWdgBounding.Height / 2) * scaletransform.ScaleX - DesignerScrollViewer.ActualHeight / 2);
                }
                e.Handled = true;
            }
        }