From ece04af23ed04a5ad4d8f2277e96bc7c41042b2c Mon Sep 17 00:00:00 2001 From: Dirkster99 Date: Mon, 12 Nov 2018 20:02:41 +0100 Subject: [PATCH] Fix for issue #9 https://github.com/xceedsoftware/wpftoolkit/issues/1403 https://github.com/xceedsoftware/wpftoolkit/issues/1119 --- .../Xceed.Wpf.AvalonDock/Layout/Extentions.cs | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) 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;