internal void DropInto(DockablePane paneDragged, DockablePane paneToDropInto)
        {
            //transfer tha contents of dragged pane (conatined in a FloatingWindow)
            //to the pane which user select, taking care of setting contents state
            //to Dock (using Dock() method of class DockablePane).
            while (paneDragged.Items.Count > 0)
            {
                ManagedContent contentToTransfer = paneDragged.RemoveContent(0);
                paneToDropInto.Items.Add(contentToTransfer);


                DockableContent dockContentToTransfer = contentToTransfer as DockableContent;

                if (dockContentToTransfer != null)
                    dockContentToTransfer.SetStateToDock();
            }


            paneToDropInto.SelectedIndex = paneToDropInto.Items.Count - 1;
            paneToDropInto.Focus();
        }
        /// <summary>
        /// Autohides/redock a dockable pane
        /// </summary>
        /// <param name="pane">Pane to auto hide/redock</param>
        internal void ToggleAutoHide(DockablePane pane)
        {
            if (!_OnApplyTemplateFlag)
            {
                Debug.WriteLine("Layout has been restored before creating DockingManager object: force WPF to apply the template...");
                ApplyTemplate();
            }

            //if pane is in auto hide state then is found
            //referenced by a DockablePaneAnchorTabGroup
            //if so redock it in its original position
            if (RemovePaneFromTabGroups(pane))
            {
                #region Pane is present in tab anchor panels
                DockableContent selectedContent =
                    _flyoutWindow != null &&
                    _flyoutWindow.ReferencedPane != null &&
                    _flyoutWindow.ReferencedPane.Items.Count > 0 ? _flyoutWindow.ReferencedPane.Items[0] as DockableContent :
                    pane.Items[0] as DockableContent;

                HideFlyoutWindow();

                ResizingPanel parentPanel = pane.Parent as ResizingPanel;
                if (parentPanel != null && parentPanel.Children.Count >= 3)
                {
                    parentPanel.AdjustPanelSizes();
                }

                //reset content state to docked
                foreach (DockableContent content in pane.Items)
                {
                    content.SetStateToDock();
                }

                pane.Focus();
                pane.SelectedItem = selectedContent;
                ActiveContent = selectedContent;
                #endregion
            }
            else
            {
                #region Pane is not auto hidden
                //Create e new group
                DockablePaneAnchorTabGroup group = new DockablePaneAnchorTabGroup();

                //associate it to the pane
                group.ReferencedPane = pane;

                DockableContent selectedContent = pane.SelectedItem as DockableContent;

                //add contents to it
                foreach (DockableContent content in pane.Items)
                {
                    DockablePaneAnchorTab tab = new DockablePaneAnchorTab();
                    tab.ReferencedContent = content;
                    //tab.Anchor = pane.Anchor;
                    //tab.Icon = content.Icon;

                    group.Children.Add(tab);
                    content.SetStateToAutoHide();
                }

                //place group under correct anchor tabpanel
                switch (pane.Anchor)
                {
                    case AnchorStyle.Left:
                        if (_leftAnchorTabPanel != null)
                            _leftAnchorTabPanel.Children.Add(group);
                        break;
                    case AnchorStyle.Top:
                        if (_topAnchorTabPanel != null)
                            _topAnchorTabPanel.Children.Add(group);
                        break;
                    case AnchorStyle.Right:
                        if (_rightAnchorTabPanel != null)
                            _rightAnchorTabPanel.Children.Add(group);
                        break;
                    case AnchorStyle.Bottom:
                        if (_bottomAnchorTabPanel != null)
                            _bottomAnchorTabPanel.Children.Add(group);
                        break;
                }

                #endregion
            }

            //refresh arrangements traversing bottom-up visual tree
            FrameworkElement parentElement = pane.Parent as FrameworkElement;

            while (parentElement != null)
            {
                parentElement.InvalidateMeasure();
                parentElement = parentElement.Parent as FrameworkElement;
            }
        }
        /// <summary>
        /// Anchor a dockable pane (<see cref="DockablePane"/>) to a border of an other dockable pane
        /// </summary>
        /// <param name="paneToAnchor">Pane to anchor</param>
        /// <param name="relativePane">Pane relative</param>
        /// <param name="anchor"></param>
        public void Anchor(DockablePane paneToAnchor, DockablePane relativePane, AnchorStyle anchor)
        {
            //ensure that content property is not empty
            EnsureContentNotEmpty();
            
            if (anchor == AnchorStyle.None)
                anchor = AnchorStyle.Right;

            //get a refernce to the resizingpanel container of relativePane
            ResizingPanel relativePaneContainer = LogicalTreeHelper.GetParent(relativePane) as ResizingPanel;
            Orientation requestedOrientation =
                (anchor == AnchorStyle.Bottom || anchor == AnchorStyle.Top) ? Orientation.Vertical : Orientation.Horizontal;

            if (relativePaneContainer == null)
            {
                Debug.Assert(relativePane.Parent == this);

                relativePaneContainer = new ResizingPanel();
                relativePaneContainer.Orientation = requestedOrientation;
                this.Content = relativePaneContainer;
                relativePaneContainer.Children.Add(relativePane);
            }

            Debug.Assert(relativePaneContainer != null, "By now we can't have a pane without a resizing panel containing it");

            #region Create and setup container panel
            if (relativePaneContainer != null)
            {
                //check if orientation is right
                if (relativePaneContainer.Orientation != requestedOrientation)
                {
                    //if the existing panel is not oriented as we want
                    //create a new one
                    ResizingPanel newPanel = new ResizingPanel();
                    newPanel.Orientation = requestedOrientation;

                    if (newPanel.Orientation == Orientation.Horizontal)
                        ResizingPanel.SetResizeHeight(newPanel, ResizingPanel.GetResizeHeight(relativePane));
                    else
                        ResizingPanel.SetResizeWidth(newPanel, ResizingPanel.GetResizeWidth(relativePane));

                    //replace relative pane in its' container panel
                    //with this new panel
                    int indexofRelativePane = relativePaneContainer.Children.IndexOf(relativePane);
                    relativePaneContainer.Children.Remove(relativePane);
                    relativePaneContainer.Children.Insert(indexofRelativePane, newPanel);

                    //now we have a panel correctly placed in the tree
                    newPanel.Children.Add(relativePane);
                    newPanel.InsertChildRelativeTo(
                        paneToAnchor, relativePane, anchor == AnchorStyle.Right || anchor == AnchorStyle.Bottom);

                    relativePaneContainer = newPanel;
                }
                else
                {
                    if (anchor == AnchorStyle.Left ||
                        anchor == AnchorStyle.Top)
                    {
                        //add new child before first (prepend)
                        relativePaneContainer.InsertChildRelativeTo(paneToAnchor,
                            relativePane, false);
                    }
                    else
                    {
                        //add new child after last (append)
                        relativePaneContainer.InsertChildRelativeTo(paneToAnchor,
                            relativePane, true);
                    }
                }


                relativePaneContainer.InvalidateMeasure();
            } 
            #endregion

            //than set the new anchor style for the pane
            paneToAnchor.Anchor = relativePane.Anchor;

            if (anchor == AnchorStyle.Left ||
                anchor == AnchorStyle.Right)
            {
                double w = Math.Min(
                    ResizingPanel.GetEffectiveSize(relativePane).Width / 2.0,
                    ResizingPanel.GetEffectiveSize(paneToAnchor).Width);
                ResizingPanel.SetResizeWidth(paneToAnchor, new GridLength(w, GridUnitType.Pixel));
                ResizingPanel.SetResizeHeight(paneToAnchor, new GridLength(1.0, GridUnitType.Star));
            }
            else
            {
                double h = Math.Min(
                    ResizingPanel.GetEffectiveSize(relativePane).Height / 2.0,
                    ResizingPanel.GetEffectiveSize(paneToAnchor).Height);
                ResizingPanel.SetResizeWidth(paneToAnchor, new GridLength(1.0, GridUnitType.Star));
                ResizingPanel.SetResizeHeight(paneToAnchor, new GridLength(h, GridUnitType.Pixel));
            }

            //refresh contents state
            foreach (DockableContent draggedContent in paneToAnchor.Items)
            {
                draggedContent.SetStateToDock();
            }

            if (relativePaneContainer != null)
                relativePaneContainer.AdjustPanelSizes();

            paneToAnchor.Focus();
        }