ContainerVisual Class
Assembly: PresentationCore (in presentationcore.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation
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.
// Create a host visual derived from the FrameworkElement class. // This class provides layout, event handling, and container support for // the child visual objects. public class MyContainerVisualHost : FrameworkElement { private ContainerVisual _containerVisual; public MyContainerVisualHost(DrawingVisual border, DrawingVisual text) { // Create a ContainerVisual to hold DrawingVisual children. _containerVisual = new ContainerVisual(); // Add children to ContainerVisual in reverse z-order (bottom to top). _containerVisual.Children.Add(border); _containerVisual.Children.Add(text); // Create parent-child relationship with host visual and ContainerVisual. this.AddVisualChild(_containerVisual); } // Provide a required override for the VisualChildrenCount property. protected override int VisualChildrenCount { get { return _containerVisual == null ? 0 : 1; } } // Provide a required override for the GetVisualChild method. protected override Visual GetVisualChild(int index) { if (_containerVisual == null) { throw new ArgumentOutOfRangeException(); } return _containerVisual; } }
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.