public override Size GetPreferredSize(ViewLayoutContext context)
{
// Remember the original display rect for restoring late
Rectangle originalRect = context.DisplayRectangle;
// Reduce available display rect by the required border sizing
if (_paletteMetrics != null)
context.DisplayRectangle = CommonHelper.ApplyPadding(Orientation, originalRect, _paletteMetrics.GetMetricPadding(State, _metricPadding));
// Cache the maximum extent of all the children
_extent = base.GetPreferredSize(context);
// Do we have a metric source for additional padding?
if (_paletteMetrics == null)
return _extent;
// Restore the original display rectangle
context.DisplayRectangle = originalRect;
// Apply padding needed outside the border of the canvas
return CommonHelper.ApplyPadding(Orientation, _extent, _paletteMetrics.GetMetricPadding(State, _metricPadding));
}