コード例 #1
0
        /// <summary>
        /// Discover the preferred size of the element.
        /// </summary>
        /// <param name="context">Layout context.</param>
        public override Size GetPreferredSize(ViewLayoutContext context)
        {
            Debug.Assert(context != null);

            // Validate incoming reference
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            // During disposal the view control will not longer exist
            if (_viewControl != null)
            {
                // Ensure the control has the correct parent
                UpdateParent(context.Control);

                // Ensure context has the correct control
                using (CorrectContextControl ccc = new CorrectContextControl(context, _viewControl))
                {
                    // Ask the view for its preferred size
                    if (_viewChild != null)
                    {
                        return(_viewChild.GetPreferredSize(context));
                    }
                }
            }

            return(Size.Empty);
        }
コード例 #2
0
 /// <summary>
 /// Discover the preferred size of the element.
 /// </summary>
 /// <param name="context">Layout context.</param>
 public override Size GetPreferredSize(ViewLayoutContext context)
 {
     return(_child.GetPreferredSize(context));
 }
コード例 #3
0
        /// <summary>
        /// Perform a layout of the elements.
        /// </summary>
        /// <param name="context">Layout context.</param>
        public override void Layout(ViewLayoutContext context)
        {
            Debug.Assert(context != null);

            // Validate incoming reference
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // We take on all the available display area
            Rectangle original = context.DisplayRectangle;

            ClientRectangle = original;

            // Layout each child
            int offset = 0;
            int space  = (_orientation == Orientation.Vertical ? ClientHeight : ClientWidth);

            for (int i = 0; i < Count; i++)
            {
                ViewBase child = this[i];

                // Find length of this item
                int length;

                // If this is the last item then it takes the remaining space
                if (i == (Count - 1))
                {
                    length = space;
                }
                else
                {
                    // Give this item an equal portion of the remainder
                    length = space / (Count - i);
                }

                // Ask child for it's own preferred size
                Size childPreferred = child.GetPreferredSize(context);

                // Size child to our relevant dimension
                if (_orientation == Orientation.Vertical)
                {
                    context.DisplayRectangle = new Rectangle(ClientRectangle.X,
                                                             ClientRectangle.Y + offset,
                                                             childPreferred.Width,
                                                             length);
                }
                else
                {
                    context.DisplayRectangle = new Rectangle(ClientRectangle.X + offset,
                                                             ClientRectangle.Y,
                                                             length,
                                                             ClientRectangle.Height);
                }

                // Ask the child to layout
                child.Layout(context);

                // Adjust running values
                offset += length;
                space  -= length;
            }

            // Put back the original display value now we have finished
            context.DisplayRectangle = original;
        }