Exemple #1
0
        /// <summary>
        /// Calculate the ideal size needed to show exactly the commands.
        /// </summary>
        /// <returns>Ideal size unless still initializing control, in which case Size.Empty</returns>
        public Size CalculateIdealSize()
        {
            // If we are not initializing then...
            if (_initCount == 0)
            {
                // Need to calculate the rectangle that exactly fits the commands
                Rectangle idealRectangle = _engine.FindIdealSize(_states, _details);

                // Increase by padding area
                if (Direction == LayoutDirection.Horizontal)
                {
                    idealRectangle.Width  += Padding.Width;
                    idealRectangle.Height += Padding.Height;
                }
                else
                {
                    idealRectangle.Width  += Padding.Height;
                    idealRectangle.Height += Padding.Width;
                }

                // Now we need to relayout again using available size, as the FindIdealSize
                // will have updated internal sizing of commands which needs to be undone.
                LayoutControl();

                return(idealRectangle.Size);
            }
            else
            {
                return(Size.Empty);
            }
        }