Exemple #1
0
        /// <summary>
        /// Animates the panel sizes
        /// </summary>
        private void AnimatePanelSizes()
        {
            double determinedWidth = (double)this.columns * (this.minimizedColumnWidth + 30);
            double aw = this.ActualWidth;
            double ah = this.ActualHeight;


            #region determine width of the app
            determinedWidth = 0;
            foreach (UIElement child in this.panels)
            {
                DragDockPanel panel = (DragDockPanel)child;
                panel.UpdateLayout();
                determinedWidth += panel.ActualWidth < this.minimizedColumnWidth ? this.minimizedColumnWidth : panel.ActualWidth;
            }
            aw = determinedWidth;
            #endregion

            if (CancelPanelResizingAnimation)
            {
                aw = determinedWidth;
            }
            else
            {
                aw = this.ActualWidth;
            }

            if (double.IsInfinity(aw) || double.IsNaN(aw) || aw == 0)
            {
                return;
            }

            // If there is not a maxmized panel...
            if (this.maximizedPanel == null)
            {
                // Animate the panel sizes to row / column sizes
                foreach (UIElement child in this.panels)
                {
                    DragDockPanel panel = (DragDockPanel)child;

                    double width  = (aw / (double)this.columns) - panel.Margin.Left - panel.Margin.Right;
                    double height = (ah / (double)this.rows) - panel.Margin.Top - panel.Margin.Bottom;

                    if (width < 0)
                    {
                        width = 0;
                    }

                    if (height < 0)
                    {
                        height = 0;
                    }

                    panel.AnimateSize(
                        width,
                        height);
                }
            }
            else
            {
                // Loop through the children
                foreach (UIElement child in this.panels)
                {
                    DragDockPanel panel =
                        (DragDockPanel)child;

                    // Set the size of the non
                    // maximized children
                    if (panel != this.maximizedPanel)
                    {
                        #region determine new width & height depending on docking axis
                        double newWidth  = this.minimizedColumnWidth - panel.Margin.Left - panel.Margin.Right;
                        double newHeight = (this.ActualHeight / (double)(this.panels.Count - 1)) - panel.Margin.Top - panel.Margin.Bottom;
                        if (this.minimizedPosition.Equals(MinimizedPositions.Bottom) || this.minimizedPosition.Equals(MinimizedPositions.Top))
                        {
                            newWidth  = (this.ActualWidth / (double)(this.panels.Count - 1)) - panel.Margin.Left - panel.Margin.Right;
                            newHeight = this.minimizedRowHeight - panel.Margin.Top - panel.Margin.Bottom;
                        }
                        #endregion

                        if (newHeight < 0)
                        {
                            newHeight = 0;
                        }

                        if (newWidth < 0)
                        {
                            newWidth = 0;
                        }

                        panel.AnimateSize(
                            newWidth,
                            newHeight);
                    }
                    else
                    {
                        #region determine new width & height depending on docking axis
                        double newWidth  = this.ActualWidth - this.minimizedColumnWidth - panel.Margin.Left - panel.Margin.Right;
                        double newHeight = this.ActualHeight - panel.Margin.Top - panel.Margin.Bottom;
                        if (this.minimizedPosition.Equals(MinimizedPositions.Bottom) || this.minimizedPosition.Equals(MinimizedPositions.Top))
                        {
                            newWidth  = this.ActualWidth - panel.Margin.Left - panel.Margin.Right;
                            newHeight = this.ActualHeight - this.minimizedRowHeight - panel.Margin.Top - panel.Margin.Bottom;
                        }
                        #endregion

                        if (newHeight < 0)
                        {
                            newHeight = 0;
                        }

                        if (newWidth < 0)
                        {
                            newWidth = 0;
                        }

                        panel.AnimateSize(
                            newWidth,
                            newHeight);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Updates the panel layout without animation
        /// This does size and position without animation
        /// </summary>
        private void UpdatePanelLayout()
        {
            double determinedWidth = (double)this.columns * (this.minimizedColumnWidth + 30);
            double aw = this.ActualWidth;
            double ah = this.ActualHeight;


            #region determine width of the app
            determinedWidth = 0;
            foreach (UIElement child in this.panels)
            {
                DragDockPanel panel = (DragDockPanel)child;
                panel.UpdateLayout();
                determinedWidth += panel.ActualWidth < this.minimizedColumnWidth? this.minimizedColumnWidth: panel.ActualWidth;
            }
            aw = determinedWidth;
            #endregion

            if (CancelPanelResizingAnimation)
            {
                aw = determinedWidth;
            }
            else
            {
                aw = this.ActualWidth;
            }

            if (double.IsInfinity(aw) || double.IsNaN(aw) || aw == 0)
            {
                return;
            }

            // If we are not in max'ed panel mode...
            if (this.maximizedPanel == null)
            {
                // Layout children as per rows and columns
                foreach (UIElement child in this.panels)
                {
                    DragDockPanel panel = (DragDockPanel)child;

                    Canvas.SetLeft(
                        panel,
                        (Grid.GetColumn(panel) * (aw / (double)this.columns)));

                    Canvas.SetTop(
                        panel,
                        (Grid.GetRow(panel) * (ah / (double)this.rows)));

                    double width  = (aw / (double)this.columns) - panel.Margin.Left - panel.Margin.Right;
                    double height = (ah / (double)this.rows) - panel.Margin.Top - panel.Margin.Bottom;

                    if (width < 0)
                    {
                        width = 0;
                    }

                    if (height < 0)
                    {
                        height = 0;
                    }

                    panel.Width  = width;
                    panel.Height = height;
                }
            }
            else
            {
                Dictionary <int, DragDockPanel> orderedPanels = new Dictionary <int, DragDockPanel>();

                // Loop through children to order them according to their
                // current row and column...
                foreach (UIElement child in this.panels)
                {
                    DragDockPanel panel = (DragDockPanel)child;

                    orderedPanels.Add(
                        (Grid.GetRow(panel) * this.columns) + Grid.GetColumn(panel),
                        panel);
                }

                // Set initial top of minimized panels to 0
                double currentOffset = 0.0;

                // For each of the panels (as ordered in the grid)
                for (int i = 0; i < orderedPanels.Count; i++)
                {
                    // If the current panel is not the maximized panel
                    if (orderedPanels[i] != this.maximizedPanel)
                    {
                        #region determine new width & height depending on docking axis
                        double newWidth  = this.minimizedColumnWidth - orderedPanels[i].Margin.Left - orderedPanels[i].Margin.Right;
                        double newHeight = (this.ActualHeight / (double)(this.panels.Count - 1)) - orderedPanels[i].Margin.Top - orderedPanels[i].Margin.Bottom;
                        if (this.minimizedPosition.Equals(MinimizedPositions.Bottom) || this.minimizedPosition.Equals(MinimizedPositions.Top))
                        {
                            newWidth  = (this.ActualWidth / (double)(this.panels.Count - 1)) - orderedPanels[i].Margin.Left - orderedPanels[i].Margin.Right;
                            newHeight = this.minimizedRowHeight - orderedPanels[i].Margin.Top - orderedPanels[i].Margin.Bottom;
                        }
                        #endregion

                        if (newHeight < 0)
                        {
                            newHeight = 0;
                        }

                        if (newWidth < 0)
                        {
                            newWidth = 0;
                        }

                        // Set the size of the panel
                        orderedPanels[i].Width  = newWidth;
                        orderedPanels[i].Height = newHeight;

                        double newX = 0;
                        double newY = currentOffset;
                        #region determin new docking coordinates
                        if (this.minimizedPosition.Equals(MinimizedPositions.Right))
                        {
                            newX = this.ActualWidth - this.minimizedColumnWidth;
                            newY = currentOffset;
                        }
                        else if (this.minimizedPosition.Equals(MinimizedPositions.Left))
                        {
                            newX = 0;
                            newY = currentOffset;
                        }
                        else if (this.minimizedPosition.Equals(MinimizedPositions.Bottom))
                        {
                            newX = currentOffset;
                            newY = this.ActualHeight - this.minimizedRowHeight;
                        }
                        else if (this.minimizedPosition.Equals(MinimizedPositions.Top))
                        {
                            newX = currentOffset;
                            newY = 0;
                        }
                        #endregion

                        // Set the position of the panel
                        Canvas.SetLeft(orderedPanels[i], newX);
                        Canvas.SetTop(orderedPanels[i], newY);

                        if (this.minimizedPosition.Equals(MinimizedPositions.Left) || this.minimizedPosition.Equals(MinimizedPositions.Right))
                        {
                            // Increment current top
                            currentOffset += this.ActualHeight / (double)(this.panels.Count - 1);
                        }
                        else
                        {
                            // Increment current left
                            currentOffset += this.ActualWidth / (double)(this.panels.Count - 1);
                        }
                    }
                    else
                    {
                        #region determine new width & height depending on docking axis
                        double newWidth  = this.ActualWidth - this.minimizedColumnWidth - orderedPanels[i].Margin.Left - orderedPanels[i].Margin.Right;
                        double newHeight = this.ActualHeight - orderedPanels[i].Margin.Top - orderedPanels[i].Margin.Bottom;
                        if (this.minimizedPosition.Equals(MinimizedPositions.Bottom) || this.minimizedPosition.Equals(MinimizedPositions.Top))
                        {
                            newWidth  = this.ActualWidth - orderedPanels[i].Margin.Left - orderedPanels[i].Margin.Right;
                            newHeight = this.ActualHeight - this.minimizedRowHeight - orderedPanels[i].Margin.Top - orderedPanels[i].Margin.Bottom;
                        }
                        #endregion

                        if (newHeight < 0)
                        {
                            newHeight = 0;
                        }

                        if (newWidth < 0)
                        {
                            newWidth = 0;
                        }

                        // Set the size of the panel
                        orderedPanels[i].Width  = newWidth;
                        orderedPanels[i].Height = newHeight;

                        #region determine new docking position
                        double newX = 0;
                        double newY = 0;
                        if (this.minimizedPosition.Equals(MinimizedPositions.Right))
                        {
                            newX = 0;
                            newY = 0;
                        }
                        else if (this.minimizedPosition.Equals(MinimizedPositions.Left))
                        {
                            newX = this.minimizedColumnWidth;
                            newY = 0;
                        }
                        else if (this.minimizedPosition.Equals(MinimizedPositions.Bottom))
                        {
                            newX = 0;
                            newY = 0;
                        }
                        else if (this.minimizedPosition.Equals(MinimizedPositions.Top))
                        {
                            newX = 0;
                            newY = this.minimizedRowHeight;
                        }
                        #endregion

                        // Set the position of the panel
                        Canvas.SetLeft(orderedPanels[i], newX);
                        Canvas.SetTop(orderedPanels[i], newY);
                    }
                }
            }
        }