diff --git a/source/Components/Xceed.Wpf.AvalonDock/Layout/Extentions.cs b/source/Components/Xceed.Wpf.AvalonDock/Layout/Extentions.cs index 4f319e1b..09c3469a 100644 --- a/source/Components/Xceed.Wpf.AvalonDock/Layout/Extentions.cs +++ b/source/Components/Xceed.Wpf.AvalonDock/Layout/Extentions.cs @@ -85,34 +85,41 @@ public static bool IsOfType( this ILayoutContainer container ) return container is T || container is S; } - public static AnchorSide GetSide( this ILayoutElement element ) - { - var parentContainer = element.Parent as ILayoutOrientableGroup; - if( parentContainer != null ) - { - var layoutPanel = parentContainer as LayoutPanel; - if( layoutPanel == null ) + public static AnchorSide GetSide(this ILayoutElement element) { - layoutPanel = parentContainer.FindParent(); + var parentContainer = element.Parent as ILayoutOrientableGroup; + if (parentContainer != null) + { + if (!parentContainer.ContainsChildOfType()) + return GetSide(parentContainer); + + foreach (var childElement in parentContainer.Children) + { + if (childElement == element || + childElement.Descendents().Contains(element)) + return parentContainer.Orientation == System.Windows.Controls.Orientation.Horizontal ? + AnchorSide.Left : AnchorSide.Top; + + var childElementAsContainer = childElement as ILayoutContainer; + if (childElementAsContainer != null && + (childElementAsContainer.IsOfType() || + childElementAsContainer.ContainsChildOfType())) + { + return parentContainer.Orientation == System.Windows.Controls.Orientation.Horizontal ? + AnchorSide.Right : AnchorSide.Bottom; + } + } + } + + Debug.Fail("Unable to find the side for an element, possible layout problem!"); + return AnchorSide.Right; } - if( (layoutPanel != null) && ( layoutPanel.Children.Count > 0 ) ) - { - if( layoutPanel.Orientation == System.Windows.Controls.Orientation.Horizontal ) - return layoutPanel.Children[ 0 ].Descendents().Contains( element ) ? AnchorSide.Left : AnchorSide.Right; - return layoutPanel.Children[ 0 ].Descendents().Contains( element ) ? AnchorSide.Top : AnchorSide.Bottom; - } - } - - Debug.Fail( "Unable to find the side for an element, possible layout problem!" ); - return AnchorSide.Right; - } - - #endregion + #endregion - #region Internal Methods + #region Internal Methods - internal static void KeepInsideNearestMonitor( this ILayoutElementForFloatingWindow paneInsideFloatingWindow ) + internal static void KeepInsideNearestMonitor( this ILayoutElementForFloatingWindow paneInsideFloatingWindow ) { Win32Helper.RECT r = new Win32Helper.RECT(); r.Left = ( int )paneInsideFloatingWindow.FloatingLeft;