Beispiel #1
0
        /// <summary>
        /// Adds the dock pane to the document container via splitting and docks it to the specified dock point
        /// </summary>
        /// <param name="pane">Pane to add</param>
        /// <param name="dockPoint">The dock point for content</param>
        public void AddDockPane(DockPane pane, ContentDockPoint dockPoint)
        {
            DocumentContainer targetContainer;

            if (CanMergeContent(dockPoint, out targetContainer))
            {
                targetContainer.AddDocument(pane);
            }
            else
            {
                SplitAndAddDocument(pane, dockPoint);
            }
        }
        /// <summary>
        /// Splits and adds document to the split window
        /// </summary>
        /// <param name="pane">The pane</param>
        /// <param name="dockPoint">The dock point</param>
        private void SplitAndAddDocument(DockPane pane, ContentDockPoint dockPoint)
        {
            DocumentContainer container = new DocumentContainer();
            Grid splitGrid = null;

            switch (dockPoint)
            {
            case ContentDockPoint.Top:
                splitGrid = SplitVertically(false);
                Grid.SetRow(container, 0);
                break;

            case ContentDockPoint.Left:
                splitGrid = SplitHorizontally(false);
                Grid.SetColumn(container, 0);
                break;

            case ContentDockPoint.Right:
                splitGrid = SplitHorizontally(true);
                Grid.SetColumn(container, 2);
                break;

            case ContentDockPoint.Bottom:
                splitGrid = SplitVertically(true);
                Grid.SetRow(container, 2);
                break;

            case ContentDockPoint.Content:
                AddDocument(pane);
                return;

                break;

            default:
                break;
            }

            container.AddDocument(pane);
            splitGrid.Children.Add(container);
        }
Beispiel #3
0
        /// <summary>
        /// Determines whether content can be merged at the specified dock point
        /// </summary>
        /// <param name="dockPoint">The dock point.</param>
        /// <param name="targetContainer">If merge can be performed, this is the target container for merge; otherwise this will be null</param>
        /// <returns>
        ///     <c>true</c> if content can be merged at the specified dock point; otherwise, <c>false</c>.
        /// </returns>
        private bool CanMergeContent(ContentDockPoint dockPoint, out DocumentContainer targetContainer)
        {
            Grid contentGrid = Content as Grid;

            targetContainer = null;

            if (contentGrid == null)
            {
                return(false);
            }

            foreach (object item in contentGrid.Children)
            {
                if (item is DocumentContainer)
                {
                    DocumentContainer container = item as DocumentContainer;

                    if (container.State == DocumentContainerState.Empty)
                    {
                        int column = Grid.GetColumn(container);
                        int row    = Grid.GetRow(container);

                        if (((dockPoint == ContentDockPoint.Top) && (row == 0)) ||
                            ((dockPoint == ContentDockPoint.Bottom) && (row == 2)) ||
                            ((dockPoint == ContentDockPoint.Left) && (column == 0)) ||
                            ((dockPoint == ContentDockPoint.Right) && (column == 2)))
                        {
                            targetContainer = container;
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
        /// <summary>
        /// Splits and adds document to the split window
        /// </summary>
        /// <param name="pane">The pane</param>
        /// <param name="dockPoint">The dock point</param>
        private void SplitAndAddDocument(DockPane pane, ContentDockPoint dockPoint)
        {
            DocumentContainer container = new DocumentContainer();
            Grid splitGrid = null;

            switch (dockPoint)
            {
                case ContentDockPoint.Top:
                    splitGrid = SplitVertically(false);
                    Grid.SetRow(container, 0);
                    break;
                case ContentDockPoint.Left:
                    splitGrid = SplitHorizontally(false);
                    Grid.SetColumn(container, 0);
                    break;
                case ContentDockPoint.Right:
                    splitGrid = SplitHorizontally(true);
                    Grid.SetColumn(container, 2);
                    break;
                case ContentDockPoint.Bottom:
                    splitGrid = SplitVertically(true);
                    Grid.SetRow(container, 2);
                    break;
                case ContentDockPoint.Content:
                    AddDocument(pane);
                    return;
                default:
                    break;
            }

            container.AddDocument(pane);
            splitGrid.Children.Add(container);
        }
        /// <summary>
        /// Determines whether content can be merged at the specified dock point
        /// </summary>
        /// <param name="dockPoint">The dock point.</param>
        /// <param name="targetContainer">If merge can be performed, this is the target container for merge; otherwise this will be null</param>
        /// <returns>
        /// 	<c>true</c> if content can be merged at the specified dock point; otherwise, <c>false</c>.
        /// </returns>
        private bool CanMergeContent(ContentDockPoint dockPoint, out DocumentContainer targetContainer)
        {
            Grid contentGrid = Content as Grid;
            targetContainer = null;

            if (contentGrid == null)
            {
                return false;
            }

            foreach (object item in contentGrid.Children)
            {
                if (item is DocumentContainer)
                {
                    DocumentContainer container = item as DocumentContainer;

                    if (container.State == DocumentContainerState.Empty)
                    {
                        int column = Grid.GetColumn(container);
                        int row = Grid.GetRow(container);

                        if (((dockPoint == ContentDockPoint.Top) && (row == 0)) ||
                             ((dockPoint == ContentDockPoint.Bottom) && (row == 2)) ||
                             ((dockPoint == ContentDockPoint.Left) && (column == 0)) ||
                             ((dockPoint == ContentDockPoint.Right) && (column == 2)))
                        {
                            targetContainer = container;
                            return true;
                        }
                    }
                }
            }

            return false;
        }
 /// <summary>
 /// Adds the dock pane to the document container via splitting and docks it to the specified dock point
 /// </summary>
 /// <param name="pane">Pane to add</param>
 /// <param name="dockPoint">The dock point for content</param>
 public void AddDockPane(DockPane pane, ContentDockPoint dockPoint)
 {
     DocumentContainer targetContainer;
     if (CanMergeContent(dockPoint, out targetContainer))
     {
         targetContainer.AddDocument(pane);
     }
     else
     {
         SplitAndAddDocument(pane, dockPoint);
     }
 }