Пример #1
0
        public void ToggleAutoHide()
        {
            #region Anchorable is already auto hidden
            if (IsAutoHidden)
            {
                var parentGroup       = Parent as LayoutAnchorGroup;
                var parentSide        = parentGroup.Parent as LayoutAnchorSide;
                var previousContainer = ((ILayoutPreviousContainer)parentGroup).PreviousContainer as LayoutAnchorablePane;

                if (previousContainer == null)
                {
                    AnchorSide side = (parentGroup.Parent as LayoutAnchorSide).Side;
                    switch (side)
                    {
                    case AnchorSide.Right:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Horizontal)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            previousContainer.DockMinWidth = this.AutoHideMinWidth;
                            parentGroup.Root.RootPanel.Children.Add(previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Horizontal
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(oldRootPanel);
                            panel.Children.Add(previousContainer);
                        }
                        break;

                    case AnchorSide.Left:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Horizontal)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            previousContainer.DockMinWidth = this.AutoHideMinWidth;
                            parentGroup.Root.RootPanel.Children.Insert(0, previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Horizontal
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(previousContainer);
                            panel.Children.Add(oldRootPanel);
                        }
                        break;

                    case AnchorSide.Top:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Vertical)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            previousContainer.DockMinHeight = this.AutoHideMinHeight;
                            parentGroup.Root.RootPanel.Children.Insert(0, previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Vertical
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(previousContainer);
                            panel.Children.Add(oldRootPanel);
                        }
                        break;

                    case AnchorSide.Bottom:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Vertical)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            previousContainer.DockMinHeight = this.AutoHideMinHeight;
                            parentGroup.Root.RootPanel.Children.Add(previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Vertical
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(oldRootPanel);
                            panel.Children.Add(previousContainer);
                        }
                        break;
                    }
                }
                else
                {
                    //I'm about to remove parentGroup, redirect any content (ie hidden contents) that point to it
                    //to previousContainer
                    LayoutRoot root = parentGroup.Root as LayoutRoot;
                    foreach (var cnt in root.Descendents().OfType <ILayoutPreviousContainer>().Where(c => c.PreviousContainer == parentGroup))
                    {
                        cnt.PreviousContainer = previousContainer;
                    }
                }


                foreach (var anchorableToToggle in parentGroup.Children.ToArray())
                {
                    previousContainer.Children.Add(anchorableToToggle);
                }

                parentSide.Children.Remove(parentGroup);
            }
            #endregion
            #region Anchorable is docked
            else if (Parent is LayoutAnchorablePane)
            {
                var root       = Root;
                var parentPane = Parent as LayoutAnchorablePane;

                var newAnchorGroup = new LayoutAnchorGroup();

                ((ILayoutPreviousContainer)newAnchorGroup).PreviousContainer = parentPane;

                foreach (var anchorableToImport in parentPane.Children.ToArray())
                {
                    newAnchorGroup.Children.Add(anchorableToImport);
                }

                //detect anchor side for the pane
                var anchorSide = parentPane.GetSide();

                switch (anchorSide)
                {
                case AnchorSide.Right:
                    root.RightSide.Children.Add(newAnchorGroup);
                    break;

                case AnchorSide.Left:
                    root.LeftSide.Children.Add(newAnchorGroup);
                    break;

                case AnchorSide.Top:
                    root.TopSide.Children.Add(newAnchorGroup);
                    break;

                case AnchorSide.Bottom:
                    root.BottomSide.Children.Add(newAnchorGroup);
                    break;
                }
            }
            #endregion
        }
 public LayoutAnchorablePaneGroup(LayoutAnchorablePane firstChild)
 {
     Children.Add(firstChild);
 }
Пример #3
0
        protected override void InternalDock()
        {
            var root = Root as LayoutRoot;
            LayoutAnchorablePane anchorablePane = null;

            if (root.ActiveContent != null &&
                root.ActiveContent != this)
            {
                //look for active content parent pane
                anchorablePane = root.ActiveContent.Parent as LayoutAnchorablePane;
            }

            if (anchorablePane == null)
            {
                //look for a pane on the right side
                anchorablePane = root.Descendents().OfType <LayoutAnchorablePane>().Where(pane => !pane.IsHostedInFloatingWindow && pane.GetSide() == AnchorSide.Right).FirstOrDefault();
            }

            if (anchorablePane == null)
            {
                //look for an available pane
                anchorablePane = root.Descendents().OfType <LayoutAnchorablePane>().FirstOrDefault();
            }


            bool added = false;

            if (root.Manager.LayoutUpdateStrategy != null)
            {
                added = root.Manager.LayoutUpdateStrategy.BeforeInsertAnchorable(root, this, anchorablePane);
            }

            if (!added)
            {
                if (anchorablePane == null)
                {
                    var mainLayoutPanel = new LayoutPanel()
                    {
                        Orientation = Orientation.Horizontal
                    };
                    if (root.RootPanel != null)
                    {
                        mainLayoutPanel.Children.Add(root.RootPanel);
                    }

                    root.RootPanel = mainLayoutPanel;
                    anchorablePane = new LayoutAnchorablePane()
                    {
                        DockWidth = new GridLength(200.0, GridUnitType.Pixel)
                    };
                    mainLayoutPanel.Children.Add(anchorablePane);
                }

                anchorablePane.Children.Add(this);
                added = true;
            }

            if (root.Manager.LayoutUpdateStrategy != null)
            {
                root.Manager.LayoutUpdateStrategy.AfterInsertAnchorable(root, this);
            }

            base.InternalDock();
        }