/// <summary> /// Initializes a new instance of a <see cref="ManipulationBehavior"/> class. /// </summary> /// <param name="pZoomAndPanControl">The manipulated control.</param> public ManipulationBehavior(ZoomAndPanControl pZoomAndPanControl) { this.mZoomAndPanControl = pZoomAndPanControl; this.mZoomAndPanControl.MouseDown += this.OnZoomAndPanControlMouseDown; this.mZoomAndPanControl.MouseMove += this.OnZoomAndPanControlMouseMove; this.mZoomAndPanControl.MouseUp += this.OnZoomAndPanControlMouseUp; this.mZoomAndPanControl.PreviewMouseWheel += this.OnZoomAndPanControlMouseWheel; FrameworkElement lContent = this.mZoomAndPanControl.Content as FrameworkElement; if (lContent != null) { lContent.MouseWheel += this.OnZoomAndPanControlMouseWheel; } this.mMouseHandlingMode = MouseHandlingMode.None; }
/// <summary> /// Called when a template has been applied to the control. /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); this.mZoomAndPanControl = this.GetTemplateChild(PART_ZOOM_AND_PAN_CONTROL) as ZoomAndPanControl; if (this.mZoomAndPanControl == null) { throw new Exception("TooledZoomAndPanControl control template not correctly defined."); } this.mManipulationBehavior = new ManipulationBehavior(this.mZoomAndPanControl); // Toolbar is not mandatory. IZoomAndPanToolbar lZoomAndPanToolbar = this.GetTemplateChild(PART_TOOLBAR) as IZoomAndPanToolbar; if (lZoomAndPanToolbar != null) { lZoomAndPanToolbar.BindToControl(this.mZoomAndPanControl); } }
/// <summary> /// Event raised when the 'ContentOffsetY' property has changed value. /// </summary> private static void OnContentOffsetYChanged(DependencyObject pObject, DependencyPropertyChangedEventArgs pEventArgs) { ZoomAndPanControl lControl = pObject as ZoomAndPanControl; if (lControl != null) { lControl.UpdateTranslationY(); if (lControl.mDisableContentFocusSync == false) { // 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. lControl.UpdateContentZoomFocusY(); } if (lControl.mDisableScrollOffsetSync == false && lControl.ScrollOwner != null) { // Notify the owning ScrollViewer that the scrollbar offsets should be updated. lControl.ScrollOwner.InvalidateScrollInfo(); } } }
/// <summary> /// Called when a template has been applied to the control. /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); this.mZoomAndPanControl = this.GetTemplateChild(PART_ZOOM_AND_PAN_CONTROL) as ZoomAndPanControl; this.mViewportOverview = this.GetTemplateChild(PART_VIEWPORT_OVERVIEW) as ViewportOverview; if (this.mZoomAndPanControl == null || this.mViewportOverview == null) { throw new Exception("OverviewControl control template not correctly defined."); } this.mZoomAndPanControl.SizeChanged += this.OnZoomAndPanControlSizeChanged; this.mViewportOverview.DragDelta += this.OnViewportOverviewDragDelta; }