/// <summary> /// Determine the size of the panel. /// </summary> /// <param name="availableSize">The available size, in logical pixels.</param> /// <returns>The size of the panel, in logical pixel.</returns> public Size Measure(Size availableSize) { IDisposable traceActivity = null; if (_trace.IsEnabled) { traceActivity = _trace.WriteEventActivity( FrameworkElement.TraceProvider.FrameworkElement_MeasureStart, FrameworkElement.TraceProvider.FrameworkElement_MeasureStop, new object[] { LoggingOwnerTypeName, Panel.GetDependencyObjectId() } ); } using (traceActivity) { //Constrain the size of the slot to the child's own constraints (it will not do it by itself) var constrainedSize = GetConstrainedSize(availableSize); var measuredSize = MeasureOverride(constrainedSize); //Constrain the output of the child's measure, as will not have applied its own //MaxWidth/MaxHeight/MinWidth/MinHeight/Width/Height var size = GetConstrainedSize(measuredSize); SetDesiredChildSize(this.Panel as View, size); return(size); } }
/// <summary> /// Determine the size of the panel. /// </summary> /// <param name="availableSize">The available size, in logical pixels.</param> /// <returns>The size of the panel, in logical pixel.</returns> public Size Measure(Size availableSize) { IDisposable traceActivity = null; if (_trace.IsEnabled) { traceActivity = _trace.WriteEventActivity( FrameworkElement.TraceProvider.FrameworkElement_MeasureStart, FrameworkElement.TraceProvider.FrameworkElement_MeasureStop, new object[] { LoggingOwnerTypeName, Panel.GetDependencyObjectId() } ); } using (traceActivity) { //Constrain the size of the slot to the child's own constraints (it will not do it by itself) var constrainedSize = GetConstrainedSize(availableSize); var measuredSize = MeasureOverride(constrainedSize); //Constrain the output of the child's measure, as will not have applied its own //MaxWidth/MaxHeight/MinWidth/MinHeight/Width/Height var size = GetConstrainedSize(measuredSize); var desiredSize = size; if (this.Panel is FrameworkElement frameworkElement && frameworkElement.Visibility == Visibility.Visible) { // DesiredSize must include margins // However, we report the size to the parent without the margins var margin = frameworkElement.Margin; // This condition is required because of the measure caching that // some systems apply (Like android UI). if (margin != Thickness.Empty) { desiredSize = new Size( desiredSize.Width + margin.Left + margin.Right, desiredSize.Height + margin.Top + margin.Bottom ); } } SetDesiredChildSize(this.Panel as View, desiredSize); return(size); } }