diff --git a/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutDocumentTabItem.cs b/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutDocumentTabItem.cs index ec5436b1..024c8685 100644 --- a/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutDocumentTabItem.cs +++ b/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutDocumentTabItem.cs @@ -24,7 +24,7 @@ This program is provided to you under the terms of the Microsoft Public namespace Xceed.Wpf.AvalonDock.Controls { - public class LayoutDocumentTabItem : Control + public class LayoutDocumentTabItem : Control { #region Members /// @@ -285,7 +285,21 @@ private void StartDraggingFloatingWindowForContent() ( ( LayoutAnchorable )this.Model ).ResetCanCloseInternal(); } var manager = this.Model.Root.Manager; - manager.StartDraggingFloatingWindowForContent( this.Model ); + + // Get psotion of this visual on screen + var pos = this.PointToScreen(new Point(0,0)); + + // Transform screen point to WPF device independent point + PresentationSource source = PresentationSource.FromVisual(this); + Point targetPoints = source.CompositionTarget.TransformFromDevice.Transform(pos); + + // Log current delta between mouse and visual for use in drag cycle + var mousePosition = this.PointToScreenDPI(Mouse.GetPosition(this)); + + Point dragDelta = new Point(mousePosition.X - targetPoints.X, + mousePosition.Y - targetPoints.Y); + + manager.StartDraggingFloatingWindowForContent( this.Model, true, dragDelta); } #endregion diff --git a/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutFloatingWindowControl.cs b/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutFloatingWindowControl.cs index 6d923945..55e32ec2 100644 --- a/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutFloatingWindowControl.cs +++ b/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutFloatingWindowControl.cs @@ -62,11 +62,23 @@ protected LayoutFloatingWindowControl( ILayoutElement model ) this.Loaded += new RoutedEventHandler( OnLoaded ); this.Unloaded += new RoutedEventHandler( OnUnloaded ); _model = model; + + DragDelta = default(Point); } #endregion #region Properties + /// + /// Gets/Sets the X,Y delta between the elemnt being dragged and the + /// mouse position. The value of this property is used during the drag + /// cycle to position the dragged item under the mouse pointer. + /// + /// Set this property on intialization to ensure that + /// the delta between mouse and control being dragged + /// remains constant. + /// + internal Point DragDelta { get; set; } #region Model @@ -443,8 +455,12 @@ private void OnActivated( object sender, EventArgs e ) Logger.InfoFormat("1> Left {0:0.00} TOP {1:0.00}", Left, Top); - Left = (mousePosition.X - (windowArea.Width - clientArea.Width) / 2.0) - 3; // BugFix Issue #6 - Top = (mousePosition.Y - ( windowArea.Height - clientArea.Height ) / 2.0) - 3; + // A second chance back up plan if DragDelta is not available + if (DragDelta == default(Point)) + DragDelta = new Point(3,3); + + Left = mousePosition.X - DragDelta.X; // BugFix Issue #6 + Top = mousePosition.Y - DragDelta.Y; _attachDrag = false; Logger.InfoFormat("2> Left {0:0.00} TOP {1:0.00}", Left, Top); diff --git a/source/Components/Xceed.Wpf.AvalonDock/DockingManager.cs b/source/Components/Xceed.Wpf.AvalonDock/DockingManager.cs index 0bc5f142..07217890 100644 --- a/source/Components/Xceed.Wpf.AvalonDock/DockingManager.cs +++ b/source/Components/Xceed.Wpf.AvalonDock/DockingManager.cs @@ -2201,7 +2201,9 @@ internal FrameworkElement GetAutoHideAreaElement() return _autohideArea; } - internal void StartDraggingFloatingWindowForContent( LayoutContent contentModel, bool startDrag = true ) + internal void StartDraggingFloatingWindowForContent( LayoutContent contentModel, + bool startDrag = true, + Point dragDelta = default(Point)) { if( !contentModel.CanFloat ) return; @@ -2267,12 +2269,13 @@ internal void StartDraggingFloatingWindowForContent( LayoutContent contentModel, Layout.FloatingWindows.Add( fw ); fwc = new LayoutAnchorableFloatingWindowControl( - fw as LayoutAnchorableFloatingWindow ) + fw as LayoutAnchorableFloatingWindow ) { Width = fwWidth, Height = fwHeight, Left = contentModel.FloatingLeft, - Top = contentModel.FloatingTop + Top = contentModel.FloatingTop, + DragDelta = dragDelta // Setup initial tool window drag delta }; Logger.InfoFormat("1> contentModel Left {0:0.00} TOP {1:0.00}", @@ -2294,7 +2297,8 @@ internal void StartDraggingFloatingWindowForContent( LayoutContent contentModel, Width = fwWidth, Height = fwHeight, Left = contentModel.FloatingLeft, - Top = contentModel.FloatingTop + Top = contentModel.FloatingTop, + DragDelta = dragDelta // Setup initial document window drag delta }; Logger.InfoFormat("End> contentModel Left {0:0.00} TOP {1:0.00}",