// Event raised on mouse down in the ZoomAndPanControl public static void MouseDown(object sender, MouseButtonEventArgs e,Panel p, ZoomAndPanControl z) { p.Focus(); Keyboard.Focus(p); mouseButtonDown = e.ChangedButton; origZoomAndPanControlMouseDownPoint = e.GetPosition(z); origContentMouseDownPoint = e.GetPosition(p); if ((Keyboard.Modifiers & ModifierKeys.Shift) != 0 && (e.ChangedButton == MouseButton.Left || e.ChangedButton == MouseButton.Right)) { // Shift + left- or right-down initiates zooming mode. mouseHandlingMode = MouseHandlingMode.Zooming; } else if (mouseButtonDown == MouseButton.Left) { // Just a plain old left-down initiates panning mode. mouseHandlingMode = MouseHandlingMode.Panning; } if (mouseHandlingMode != MouseHandlingMode.None) { // Capture the mouse so that we eventually receive the mouse up event. z.CaptureMouse(); e.Handled = true; } }
// Event raised on mouse move in the ZoomAndPanControl public static void MouseMove(object sender, MouseEventArgs e, Panel p,ZoomAndPanControl z) { if (mouseHandlingMode == MouseHandlingMode.Panning) { // // The user is left-dragging the mouse. // Pan the viewport by the appropriate amount. // Point curContentMousePoint = e.GetPosition(p); Vector dragOffset = curContentMousePoint - origContentMouseDownPoint; z.ContentOffsetX -= dragOffset.X; z.ContentOffsetY -= dragOffset.Y; e.Handled = true; } }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: #line 14 "..\..\OverviewWindow.xaml" ((SampleCode.OverviewWindow)(target)).MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.Window_MouseDown); #line default #line hidden return; case 2: this.overview = ((ZoomAndPan.ZoomAndPanControl)(target)); #line 156 "..\..\OverviewWindow.xaml" this.overview.Loaded += new System.Windows.RoutedEventHandler(this.overview_Loaded); #line default #line hidden #line 157 "..\..\OverviewWindow.xaml" this.overview.SizeChanged += new System.Windows.SizeChangedEventHandler(this.overview_SizeChanged); #line default #line hidden return; case 3: this.networkControl = ((NetworkUI.NetworkView)(target)); return; case 4: this.overviewZoomRectThumb = ((System.Windows.Controls.Primitives.Thumb)(target)); #line 191 "..\..\OverviewWindow.xaml" this.overviewZoomRectThumb.DragDelta += new System.Windows.Controls.Primitives.DragDeltaEventHandler(this.overviewZoomRectThumb_DragDelta); #line default #line hidden return; } this._contentLoaded = true; }
/// <summary> /// Event raised when the 'ContentOffsetY' property has changed value. /// </summary> private static void ContentOffsetY_PropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { ZoomAndPanControl c = (ZoomAndPanControl)o; c.UpdateTranslationY(); // Normally want to automatically update content focus when content offset changes. // Although this is disabled using 'disableContentFocusSync' when content offset changes due to in-progress zooming. if (!c.disableContentFocusSync) { c.UpdateContentZoomFocusY(); } // Raise an event to let users of the control know that the content offset has changed. if (c.ContentOffsetYChanged != null) { c.ContentOffsetYChanged(c, EventArgs.Empty); } // Notify the owning ScrollViewer that the scrollbar offsets should be updated. c.UpdateScrollOffsets(); }
// Event raised on mouse up in the ZoomAndPanControl public static void MouseUp(object sender, MouseButtonEventArgs e,ZoomAndPanControl z) { if (mouseHandlingMode != MouseHandlingMode.None) { if (mouseHandlingMode == MouseHandlingMode.Zooming) { if (mouseButtonDown == MouseButton.Left) { // Shift + left-click zooms in on the content. ZoomIn(z,origContentMouseDownPoint); } else if (mouseButtonDown == MouseButton.Right) { // Shift + left-click zooms out from the content. ZoomOut(z, origContentMouseDownPoint); } } z.ReleaseMouseCapture(); mouseHandlingMode = MouseHandlingMode.None; e.Handled = true; } }
/// <summary> /// Event raised 'MinContentScale' or 'MaxContentScale' has changed. /// </summary> private static void MinOrMaxContentScale_PropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { ZoomAndPanControl c = (ZoomAndPanControl)o; c.ContentScale = Math.Min(Math.Max(c.ContentScale, c.MinContentScale), c.MaxContentScale); }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: #line 13 "..\..\..\Views\ZoomControl.xaml" ((MKView.Views.ZoomControl)(target)).MouseWheel += new System.Windows.Input.MouseWheelEventHandler(this.UserControl_MouseWheel); #line default #line hidden return; case 2: #line 52 "..\..\..\Views\ZoomControl.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.ZoomOut_Executed); #line default #line hidden return; case 3: #line 56 "..\..\..\Views\ZoomControl.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.ZoomIn_Executed); #line default #line hidden return; case 4: #line 60 "..\..\..\Views\ZoomControl.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.JumpBackToPrevZoom_Executed); #line default #line hidden #line 61 "..\..\..\Views\ZoomControl.xaml" ((System.Windows.Input.CommandBinding)(target)).CanExecute += new System.Windows.Input.CanExecuteRoutedEventHandler(this.JumpBackToPrevZoom_CanExecuted); #line default #line hidden return; case 5: #line 65 "..\..\..\Views\ZoomControl.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.Fill_Executed); #line default #line hidden return; case 6: #line 69 "..\..\..\Views\ZoomControl.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.OneHundredPercent_Executed); #line default #line hidden return; case 7: this.scroller = ((System.Windows.Controls.ScrollViewer)(target)); return; case 8: this.zoomAndPanControl = ((ZoomAndPan.ZoomAndPanControl)(target)); #line 171 "..\..\..\Views\ZoomControl.xaml" this.zoomAndPanControl.MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.zoomAndPanControl_MouseDown); #line default #line hidden #line 172 "..\..\..\Views\ZoomControl.xaml" this.zoomAndPanControl.MouseUp += new System.Windows.Input.MouseButtonEventHandler(this.zoomAndPanControl_MouseUp); #line default #line hidden #line 173 "..\..\..\Views\ZoomControl.xaml" this.zoomAndPanControl.MouseMove += new System.Windows.Input.MouseEventHandler(this.zoomAndPanControl_MouseMove); #line default #line hidden #line 174 "..\..\..\Views\ZoomControl.xaml" this.zoomAndPanControl.MouseWheel += new System.Windows.Input.MouseWheelEventHandler(this.zoomAndPanControl_MouseWheel); #line default #line hidden #line 175 "..\..\..\Views\ZoomControl.xaml" this.zoomAndPanControl.MouseDoubleClick += new System.Windows.Input.MouseButtonEventHandler(this.zoomAndPanControl_MouseDoubleClick); #line default #line hidden return; case 9: this.content = ((System.Windows.Controls.Viewbox)(target)); return; case 10: this.dragZoomCanvas = ((System.Windows.Controls.Canvas)(target)); return; case 11: this.dragZoomBorder = ((System.Windows.Controls.Border)(target)); return; } this._contentLoaded = true; }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.mainWindow = ((SampleCode.MainWindow)(target)); #line 16 "..\..\MainWindow.xaml" this.mainWindow.Loaded += new System.Windows.RoutedEventHandler(this.MainWindow_Loaded); #line default #line hidden return; case 3: #line 481 "..\..\MainWindow.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.DeleteSelectedNodes_Executed); #line default #line hidden return; case 4: #line 485 "..\..\MainWindow.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.CreateNode_Executed); #line default #line hidden return; case 5: #line 489 "..\..\MainWindow.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.DeleteNode_Executed); #line default #line hidden return; case 6: #line 493 "..\..\MainWindow.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.DeleteConnection_Executed); #line default #line hidden return; case 7: #line 497 "..\..\MainWindow.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.ZoomOut_Executed); #line default #line hidden return; case 8: #line 501 "..\..\MainWindow.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.ZoomIn_Executed); #line default #line hidden return; case 9: #line 505 "..\..\MainWindow.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.JumpBackToPrevZoom_Executed); #line default #line hidden #line 506 "..\..\MainWindow.xaml" ((System.Windows.Input.CommandBinding)(target)).CanExecute += new System.Windows.Input.CanExecuteRoutedEventHandler(this.JumpBackToPrevZoom_CanExecuted); #line default #line hidden return; case 10: #line 510 "..\..\MainWindow.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.FitContent_Executed); #line default #line hidden return; case 11: #line 514 "..\..\MainWindow.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.Fill_Executed); #line default #line hidden return; case 12: #line 518 "..\..\MainWindow.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.OneHundredPercent_Executed); #line default #line hidden return; case 13: this.zoomAndPanControl = ((ZoomAndPan.ZoomAndPanControl)(target)); return; case 14: this.networkControl = ((NetworkUI.NetworkView)(target)); #line 779 "..\..\MainWindow.xaml" this.networkControl.ConnectionDragStarted += new NetworkUI.ConnectionDragStartedEventHandler(this.networkControl_ConnectionDragStarted); #line default #line hidden #line 780 "..\..\MainWindow.xaml" this.networkControl.QueryConnectionFeedback += new NetworkUI.QueryConnectionFeedbackEventHandler(this.networkControl_QueryConnectionFeedback); #line default #line hidden #line 781 "..\..\MainWindow.xaml" this.networkControl.ConnectionDragging += new NetworkUI.ConnectionDraggingEventHandler(this.networkControl_ConnectionDragging); #line default #line hidden #line 782 "..\..\MainWindow.xaml" this.networkControl.ConnectionDragCompleted += new NetworkUI.ConnectionDragCompletedEventHandler(this.networkControl_ConnectionDragCompleted); #line default #line hidden #line 784 "..\..\MainWindow.xaml" this.networkControl.MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.networkControl_MouseDown); #line default #line hidden #line 785 "..\..\MainWindow.xaml" this.networkControl.MouseUp += new System.Windows.Input.MouseButtonEventHandler(this.networkControl_MouseUp); #line default #line hidden #line 786 "..\..\MainWindow.xaml" this.networkControl.MouseMove += new System.Windows.Input.MouseEventHandler(this.networkControl_MouseMove); #line default #line hidden #line 787 "..\..\MainWindow.xaml" this.networkControl.MouseWheel += new System.Windows.Input.MouseWheelEventHandler(this.networkControl_MouseWheel); #line default #line hidden return; case 15: this.dragZoomCanvas = ((System.Windows.Controls.Canvas)(target)); return; case 16: this.dragZoomBorder = ((System.Windows.Controls.Border)(target)); return; } this._contentLoaded = true; }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: #line 12 "..\..\OverviewWindow.xaml" ((ZoomAndPanSample.OverviewWindow)(target)).MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.Window_MouseDown); #line default #line hidden return; case 2: this.overview = ((ZoomAndPan.ZoomAndPanControl)(target)); #line 46 "..\..\OverviewWindow.xaml" this.overview.SizeChanged += new System.Windows.SizeChangedEventHandler(this.overview_SizeChanged); #line default #line hidden return; case 3: #line 55 "..\..\OverviewWindow.xaml" ((System.Windows.Controls.Grid)(target)).SizeChanged += new System.Windows.SizeChangedEventHandler(this.overview_SizeChanged); #line default #line hidden return; case 4: this.content = ((System.Windows.Controls.ItemsControl)(target)); return; case 5: this.overviewZoomRectThumb = ((System.Windows.Controls.Primitives.Thumb)(target)); #line 95 "..\..\OverviewWindow.xaml" this.overviewZoomRectThumb.DragDelta += new System.Windows.Controls.Primitives.DragDeltaEventHandler(this.overviewZoomRectThumb_DragDelta); #line default #line hidden return; } this._contentLoaded = true; }
// Zoom in/out centered on the specified point (in content coordinates). public static void ZoomAboutPoint(double newContentScale, Point contentZoomFocus,ZoomAndPanControl z) { newContentScale = Math.Min(Math.Max(newContentScale, z.MinContentScale), z.MaxContentScale); double screenSpaceZoomOffsetX = (contentZoomFocus.X - z.ContentOffsetX) * z.ContentScale; double screenSpaceZoomOffsetY = (contentZoomFocus.Y - z.ContentOffsetY) * z.ContentScale; double contentSpaceZoomOffsetX = screenSpaceZoomOffsetX / newContentScale; double contentSpaceZoomOffsetY = screenSpaceZoomOffsetY / newContentScale; double newContentOffsetX = contentZoomFocus.X - contentSpaceZoomOffsetX; double newContentOffsetY = contentZoomFocus.Y - contentSpaceZoomOffsetY; z.ContentScale = newContentScale; z.ContentOffsetX = newContentOffsetX; z.ContentOffsetY = newContentOffsetY; }
// Zoom the viewport in by a small increment public static void ZoomIn(ZoomAndPanControl z, Point contentZoomCenter) { z.ZoomAboutPoint(z.ContentScale + 0.1, contentZoomCenter); }
// Event raised by rotating the mouse wheel public static void MouseWheel(object sender, MouseWheelEventArgs e, ZoomAndPanControl z,Panel p) { e.Handled = true; if (e.Delta > 0) { Point curContentMousePoint = e.GetPosition(p); ZoomIn(z,curContentMousePoint); } else if (e.Delta < 0) { Point curContentMousePoint = e.GetPosition(p); ZoomOut(z,curContentMousePoint); } }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: #line 9 "..\..\MainWindow.xaml" ((ZoomAndPanSample.MainWindow)(target)).Loaded += new System.Windows.RoutedEventHandler(this.MainWindow_Loaded); #line default #line hidden return; case 3: #line 151 "..\..\MainWindow.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.ZoomOut_Executed); #line default #line hidden return; case 4: #line 155 "..\..\MainWindow.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.ZoomIn_Executed); #line default #line hidden return; case 5: #line 159 "..\..\MainWindow.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.JumpBackToPrevZoom_Executed); #line default #line hidden #line 160 "..\..\MainWindow.xaml" ((System.Windows.Input.CommandBinding)(target)).CanExecute += new System.Windows.Input.CanExecuteRoutedEventHandler(this.JumpBackToPrevZoom_CanExecuted); #line default #line hidden return; case 6: #line 164 "..\..\MainWindow.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.Fill_Executed); #line default #line hidden return; case 7: #line 168 "..\..\MainWindow.xaml" ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.OneHundredPercent_Executed); #line default #line hidden return; case 8: this.zoomAndPanControl = ((ZoomAndPan.ZoomAndPanControl)(target)); #line 300 "..\..\MainWindow.xaml" this.zoomAndPanControl.MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.zoomAndPanControl_MouseDown); #line default #line hidden #line 301 "..\..\MainWindow.xaml" this.zoomAndPanControl.MouseUp += new System.Windows.Input.MouseButtonEventHandler(this.zoomAndPanControl_MouseUp); #line default #line hidden #line 302 "..\..\MainWindow.xaml" this.zoomAndPanControl.MouseMove += new System.Windows.Input.MouseEventHandler(this.zoomAndPanControl_MouseMove); #line default #line hidden #line 303 "..\..\MainWindow.xaml" this.zoomAndPanControl.MouseWheel += new System.Windows.Input.MouseWheelEventHandler(this.zoomAndPanControl_MouseWheel); #line default #line hidden #line 304 "..\..\MainWindow.xaml" this.zoomAndPanControl.MouseDoubleClick += new System.Windows.Input.MouseButtonEventHandler(this.zoomAndPanControl_MouseDoubleClick); #line default #line hidden return; case 9: this.content = ((System.Windows.Controls.ListBox)(target)); return; case 10: this.dragZoomCanvas = ((System.Windows.Controls.Canvas)(target)); return; case 11: this.dragZoomBorder = ((System.Windows.Controls.Border)(target)); return; } this._contentLoaded = true; }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.ZoomAndPan = ((ZoomAndPan.ZoomAndPanControl)(target)); return; case 2: this.ImageCanvas = ((System.Windows.Controls.Canvas)(target)); return; } this._contentLoaded = true; }