The ContainerVisual class is used as a container for a collection of Visual objects. The DrawingVisual class derives from the ContainerVisual class, allowing it to contain a collection of visual objects.

The following example shows how to create a ContainerVisual object that is used as the parent for two DrawingVisual objects. Objects that are added to the ContainerVisual object must be added in reverse z-order (bottom to top) to ensure they are rendering in the correct drawing order. In order for the visual tree to be enumerated correctly, the example provides overridden implementations of the GetVisualChild method and VisualChildrenCount property.