This documentation is archived and is not being maintained.

VisualCollection Class

Represents an ordered collection of Visual objects.

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)

public sealed class VisualCollection : ICollection, 
You cannot directly create an instance of this class in XAML.

A VisualCollection has implied context affinity. If a procedure attempts to access the VisualCollection from a different context than the context of the owning ContainerVisual, an exception is thrown.

The following example shows how to create a VisualCollection and add members to it.

// 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 MyVisualHost : FrameworkElement
    // Create a collection of child visual objects. 
    private VisualCollection _children;

    public MyVisualHost()
        _children = new VisualCollection(this);

        // Add the event handler for MouseLeftButtonUp. 
        this.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(MyVisualHost_MouseLeftButtonUp);

For the complete sample, see Hit Test Using DrawingVisuals Sample.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0