Dirkster99/AvalonDock

LayoutAnchorSide don't work good in new version of 4.71.2

yuyue2013 opened this issue · 0 comments

i was newer of wpf. and i was in learning the code of edi. i find it's Layout.config is in the folder xxx\AppData\Roaming\Edi. if i use AvalonDock of version 4.60.1. even if the folder xxx\AppData\Roaming\Edi don't have Layout.config file inside it also can when start it have the toolspanel; but if i update the AvalonDock to 4.71.2. then if i start the app without Layout.config file. then the toolspanel will don't display. and need restart let it load from Layout.config then can show the toolspanel.

        public bool BeforeInsertAnchorable(LayoutRoot layout,
                                           LayoutAnchorable anchorableToShow,
                                           ILayoutContainer destinationContainer)
        {
            if (anchorableToShow.Content is IToolWindow)
            {
                IToolWindow tool = anchorableToShow.Content as IToolWindow;

                var preferredLocation = tool.PreferredLocation;

                LayoutAnchorGroup layoutGroup = null;

                switch (preferredLocation)
                {
                    case PaneLocation.Left:
                        layoutGroup = FindAnchorableGroup(layout, preferredLocation);
                        break;

                    case PaneLocation.Right:
                        layoutGroup = FindAnchorableGroup(layout, preferredLocation);
                        break;

                    case PaneLocation.Bottom:
                        layoutGroup = FindAnchorableGroup(layout, preferredLocation);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                }

                if (layoutGroup != null)
                {
                    ////group.InsertChildAt(0, anchorableToShow);
                    anchorableToShow.CanDockAsTabbedDocument = false;
                    layoutGroup.Children.Add(anchorableToShow);
                }

                return true;
            }

            return false;
        }

    private static LayoutAnchorGroup FindAnchorableGroup(LayoutRoot layout,
                                                         PaneLocation location)
        {
            try
            {
                LayoutAnchorSide panelGroupParent;

                switch (location)
                {
                    case PaneLocation.Left:
                        panelGroupParent = layout.LeftSide;
                        break;

                    case PaneLocation.Right:
                        panelGroupParent = layout.RightSide;
                        break;

                    case PaneLocation.Bottom:
                        panelGroupParent = layout.BottomSide;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException("location:" + location);
                }

                if (panelGroupParent.Children.Count == 0)
                {
                    var layoutAnchorGroup = new LayoutAnchorGroup();

                    panelGroupParent.Children.Add(layoutAnchorGroup);


                    return layoutAnchorGroup;
                }


                return panelGroupParent.Children[0];

            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message); 
                //Logger.Error(exp);
            }

            return null;
        }

the problem is "layoutGroup.Children.Add(anchorableToShow)" don't effect the display anymore.