Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
VisualCollection Class
Collapse the table of content
Expand the table of content

VisualCollection Class

Represents an ordered collection of Visual objects.


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

public sealed class VisualCollection : ICollection, 

The VisualCollection type exposes the following members.

Public methodVisualCollectionInitializes a new instance of the VisualCollection class.

Public propertyCapacityGets or sets the number of elements that the VisualCollection can contain.
Public propertyCountGets the number of elements in the collection.
Public propertyIsReadOnlyGets a value that indicates whether the VisualCollection is read-only.
Public propertyIsSynchronizedGets a value that indicates whether access to the VisualCollection is synchronized (thread-safe).
Public propertyItemGets or sets the Visual that is stored at the zero-based index of the VisualCollection.
Public propertySyncRootGets an object that can be used to synchronize access to the VisualCollection.

Public methodAddAppends a Visual to the end of the VisualCollection.
Public methodClearRemoves all elements from the VisualCollection.
Public methodContainsReturns a Boolean value that indicates whether the specified Visual is contained in the collection.
Public methodCopyTo(Array, Int32)Copies the items in the collection to an array, starting at a specific array index.
Public methodCopyTo(Visual[], Int32)Copies the current collection into the passed Visual array.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetEnumeratorRetrieves an enumerator that can iterate through the VisualCollection.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIndexOfReturns the zero-based index of the Visual.
Public methodInsertInserts an element into the VisualCollection at the specified index.
Public methodRemoveRemoves the specified Visual object from the VisualCollection.
Public methodRemoveAtRemoves the visual object at the specified index in the VisualCollection.
Public methodRemoveRangeRemoves a range of visual objects from the VisualCollection.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

Public Extension MethodAsParallel()Overloaded. Enables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension MethodAsParallel()Overloaded. (Defined by ParallelEnumerable.)
Public Extension MethodAsQueryable()Overloaded. Converts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodAsQueryable()Overloaded. (Defined by Queryable.)
Public Extension MethodCast<TResult>()Overloaded. Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodCast<TResult>()Overloaded. (Defined by Enumerable.)
Public Extension MethodOfType<TResult>()Overloaded. Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Public Extension MethodOfType<TResult>()Overloaded. (Defined by Enumerable.)

Explicit interface implemetationPrivate methodIEnumerable.GetEnumeratorThis member supports the WPF infrastructure and is not intended to be used directly from your code. For a description of this member, see GetEnumerator.

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.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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