public override Size GetPreferredSize(ViewLayoutContext context)
{
// Ensure that child elements have correct palette state
CheckPaletteState(context);
// A change in state always causes a size and layout calculation
if (_cacheState != State)
{
MakeDirty();
_cacheState = State;
}
// If the palette has changed since we last calculated
if (_ribbon.DirtyPaletteCounter != _dirtyPaletteSize)
{
// Get the preferred size of the contained content
_preferredSize = base.GetPreferredSize(context);
// Add on the preferred border sizing
Padding preferredBorder = PreferredBorder;
_preferredSize = new Size(_preferredSize.Width + preferredBorder.Horizontal,
_preferredSize.Height + preferredBorder.Vertical);
// Cached value is valid till dirty palette noticed
_dirtyPaletteSize = _ribbon.DirtyPaletteCounter;
}
return _preferredSize;
}