VisualCollection Class

 

Represents an ordered collection of Visual objects.

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

System.Object
  System.Windows.Media.VisualCollection

public sealed class VisualCollection : ICollection, IEnumerable

NameDescription
System_CAPS_pubmethodVisualCollection(Visual)

Initializes a new instance of the VisualCollection class.

NameDescription
System_CAPS_pubpropertyCapacity

Gets or sets the number of elements that the VisualCollection can contain.

System_CAPS_pubpropertyCount

Gets the number of elements in the collection.

System_CAPS_pubpropertyIsReadOnly

Gets a value that indicates whether the VisualCollection is read-only.

System_CAPS_pubpropertyIsSynchronized

Gets a value that indicates whether access to the VisualCollection is synchronized (thread-safe).

System_CAPS_pubpropertyItem[Int32]

Gets or sets the Visual that is stored at the zero-based index of the VisualCollection.

System_CAPS_pubpropertySyncRoot

Gets an object that can be used to synchronize access to the VisualCollection.

NameDescription
System_CAPS_pubmethodAdd(Visual)

Appends a Visual to the end of the VisualCollection.

System_CAPS_pubmethodClear()

Removes all elements from the VisualCollection.

System_CAPS_pubmethodContains(Visual)

Returns a Boolean value that indicates whether the specified Visual is contained in the collection.

System_CAPS_pubmethodCopyTo(Array, Int32)

Copies the items in the collection to an array, starting at a specific array index.

System_CAPS_pubmethodCopyTo(Visual[], Int32)

Copies the current collection into the passed Visual array.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodGetEnumerator()

Retrieves an enumerator that can iterate through the VisualCollection.

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodIndexOf(Visual)

Returns the zero-based index of the Visual.

System_CAPS_pubmethodInsert(Int32, Visual)

Inserts an element into the VisualCollection at the specified index.

System_CAPS_pubmethodRemove(Visual)

Removes the specified Visual object from the VisualCollection.

System_CAPS_pubmethodRemoveAt(Int32)

Removes the visual object at the specified index in the VisualCollection.

System_CAPS_pubmethodRemoveRange(Int32, Int32)

Removes a range of visual objects from the VisualCollection.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodIEnumerable.GetEnumerator()

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

NameDescription
System_CAPS_pubmethodAsParallel()

Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.)

System_CAPS_pubmethodAsQueryable()

Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.)

System_CAPS_pubmethodCast<TResult>()

Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.)

System_CAPS_pubmethodOfType<TResult>()

Filters the elements of an IEnumerable based on a specified type.(Defined by Enumerable.)

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);
    }
System_CAPS_noteNote

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

.NET Framework
Available since 3.0

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

Return to top
Show: