Workspace Hierarchy
One unique feature of the KryptonWorkspace control is the hierarchical structure to the layout definition. It means you can easily and quickly create complex layouts for your document area. But this strength is also a potential weakness because moving pages around could cause the structure to become inefficient and leave redundant entries.
To prevent this happening there are some flags that indicate how to perform a compacting phase just before the layout of the contents occurs. Each of the compact flags is used to resolve a potential problem. The flags are exposed as the CompactFlags property of the KryptonWorkspace.
CompactFlags.RemoveEmptyCells
Using drag and drop you can transfer a page from one to cell to another. If you remove the last page in the cell you are left with a cell that has no pages. Some applications may want this to happen but many others would prefer the cell be automatically removed as an empty cell is redundant. When this flag is set the compacting phase will search for any cells that have no pages defined and remove them from the hierarchy.
CompactFlags.RemoveEmptySequences
Removing empty cells can result in a workspace sequence existing that has no contents. Once all the cells contained in the sequence have been removed we are left with a redundant sequence. The user will not see the sequence as it is likely to be zero sized but it still exists in the hierarchy. During compacting this flag will search for sequences that have no children and automatically remove them.
CompactFlags.PromoteLeafs
A more subtle scenario involves a sequence that contains just a single child. If a sequence contains just a single child item then that sequence itself is redundant as it only encloses one item. This flag will promote the single child into the place of the sequence and delete the no longer needed sequence.
This situation occurs if you used drag and drop to move pages around. You can end up with a sequence that contains a single sequence child that contains yet another single sequence child and so forth. Although you would not see any visual impact it is clearly inefficient to have long chains of single sequences.
CompactFlags.AtLeastOneVisibleCell
Last but by no means least is a flag that ensures we always have at least one visible cell in the workspace. If the user deletes the last showing page in the last showing cell then the RemoveEmptyCells flag above would remove that last cell and leave the workspace area blank. Some applications require that there is always at least one cell showing even if it has no pages in it. This flag will ensure that is the case.
Layout and Compacting
By default all the above compact flags are set and this ensures that the child hierarchy is always small and efficient. Compacting occurs at the start of control layout activity and so you do not need to worry that it wil be applied whilst you are programmatically changing the structure. So you can make many changes and the compacting will not interfere until the OnLayout is processed. If you are worried then simply wrap your changes inside the SuspendLayout/ResumeLayout pair of commands.