Skip to main content
.NET Framework Class Library
VisualCollection Class

Represents an ordered collection of Visual objects.

Inheritance Hierarchy
SystemObject
  System.Windows.MediaVisualCollection

Namespace:   System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)
Syntax
Public NotInheritable Class VisualCollection _
	Implements [%$TOPIC/ms635644_en-us_VS_110_3_0_0_0_0%], [%$TOPIC/ms635644_en-us_VS_110_3_0_0_0_1%]
public sealed class VisualCollection : [%$TOPIC/ms635644_en-us_VS_110_3_0_1_0_0%], 
	[%$TOPIC/ms635644_en-us_VS_110_3_0_1_0_1%]
public ref class VisualCollection sealed : [%$TOPIC/ms635644_en-us_VS_110_3_0_2_0_0%], 
	[%$TOPIC/ms635644_en-us_VS_110_3_0_2_0_1%]
[<[%$TOPIC/ms635644_en-us_VS_110_3_0_3_0_0%]>]
type VisualCollection =  
    class 
        interface [%$TOPIC/ms635644_en-us_VS_110_3_0_3_0_1%] 
        interface [%$TOPIC/ms635644_en-us_VS_110_3_0_3_0_2%] 
    end
public final class VisualCollection implements [%$TOPIC/ms635644_en-us_VS_110_3_0_4_0_0%], [%$TOPIC/ms635644_en-us_VS_110_3_0_4_0_1%]

The VisualCollection type exposes the following members.

Constructors
  NameDescription
Public method VisualCollectionInitializes a new instance of the VisualCollection class.
Top
Properties
  NameDescription
Public property CapacityGets or sets the number of elements that the VisualCollection can contain.
Public property CountGets the number of elements in the collection.
Public property IsReadOnlyGets a value that indicates whether the VisualCollection is read-only.
Public property IsSynchronizedGets a value that indicates whether access to the VisualCollection is synchronized (thread-safe).
Public property ItemGets or sets the Visual that is stored at the zero-based index of the VisualCollection.
Public property SyncRootGets an object that can be used to synchronize access to the VisualCollection.
Top
Methods
  NameDescription
Public method AddAppends a Visual to the end of the VisualCollection.
Public method ClearRemoves all elements from the VisualCollection.
Public method ContainsReturns a Boolean value that indicates whether the specified Visual is contained in the collection.
Public method CopyTo(Array, Int32)Copies the items in the collection to an array, starting at a specific array index.
Public method CopyTo(Visual, Int32)Copies the current collection into the passed Visual array.
Public method Equals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public method GetEnumeratorRetrieves an enumerator that can iterate through the VisualCollection.
Public method GetHashCodeServes as the default hash function. (Inherited from Object.)
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Public method IndexOfReturns the zero-based index of the Visual.
Public method InsertInserts an element into the VisualCollection at the specified index.
Public method RemoveRemoves the specified Visual object from the VisualCollection.
Public method RemoveAtRemoves the visual object at the specified index in the VisualCollection.
Public method RemoveRangeRemoves a range of visual objects from the VisualCollection.
Public method ToStringReturns a string that represents the current object. (Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension Method AsParallelOverloaded. Enables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension Method AsParallelOverloaded. (Defined by ParallelEnumerable.)
Public Extension Method AsQueryableOverloaded. Converts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension Method AsQueryableOverloaded. (Defined by Queryable.)
Public Extension Method CastTResultOverloaded. Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension Method CastTResultOverloaded. (Defined by Enumerable.)
Public Extension Method OfTypeTResultOverloaded. Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Public Extension Method OfTypeTResultOverloaded. (Defined by Enumerable.)
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implemetation Private method IEnumerableGetEnumeratorThis member supports the WPF infrastructure and is not intended to be used directly from your code. For a description of this member, see GetEnumerator.
Top
Remarks

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.

Examples

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
		Inherits FrameworkElement
		' Create a collection of child visual objects.
		Private _children As VisualCollection

		Public Sub New()
			_children = New VisualCollection(Me)
			_children.Add(CreateDrawingVisualRectangle())
			_children.Add(CreateDrawingVisualText())
			_children.Add(CreateDrawingVisualEllipses())

			' Add the event handler for MouseLeftButtonUp.
			AddHandler MouseLeftButtonUp, AddressOf MyVisualHost_MouseLeftButtonUp
		End Sub
// 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.

Version Information

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.