VisualCollection Class

Represents an ordered collection of Visual objects.

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

public final class VisualCollection implements ICollection, IEnumerable
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);
        _children.Add(CreateDrawingVisualRectangle());
        _children.Add(CreateDrawingVisualText());
        _children.Add(CreateDrawingVisualEllipses());

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

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

System.Object
  System.Windows.Media.VisualCollection

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
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft