public UIElementCollection Children

/// <summary>/// Returns a UIElementCollection of children for user to add/remove children manually/// Returns read-only collection if Panel is data-bound (no manual control of children is possible,/// the associated ItemsControl completely overrides children)/// Note: the derived Panel classes should never use this collection for/// internal purposes like in their MeasureOverride or ArrangeOverride./// They should use InternalChildren instead, because InternalChildren/// is always present and either is a mirror of public Children collection (in case of Direct Panel)/// or is generated from data binding./// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public UIElementCollection Children
{
get
{
//When we will change from UIElementCollection to IList<UIElement>, we might//consider returning a wrapper IList here which coudl be read-only for mutating methods//while INternalChildren could be R/W even in case of Generator attached.return InternalChildren;
}
}

privatebool VerifyBoundState()
{
// If the panel becomes "unbound" while attached to a generator, this// method detaches it and makes it really behave like "unbound." This// can happen because of a style change, a theme change, etc. It returns// the correct "bound" state, after the dust has settled.//// This is really a workaround for a more general problem that the panel// needs to release resources (an event handler) when it is "out of the tree."// Currently, there is no good notification for when this happens.bool isItemsHost = (ItemsControl.GetItemsOwnerInternal(this) != null);
if (isItemsHost)
{
if (_itemContainerGenerator == null)
{
// Transitioning from being unbound to bound
ClearChildren();
}
return (_itemContainerGenerator != null);
}
else
{
if (_itemContainerGenerator != null)
{
// Transitioning from being bound to unbound
DisconnectFromGenerator();
ClearChildren();
}
returnfalse;
}
}

EnsureGenerator

internalvoid EnsureGenerator()
{
Debug.Assert(IsItemsHost, "Should be invoked only on an ItemsHost panel");
if (_itemContainerGenerator == null)
{
// First access on an items presenter panel
ConnectToGenerator();
// Children of this panel should not have their logical parent reset
EnsureEmptyChildren(/* logicalParent = */null);
GenerateChildren();
}
}