This topic has not yet been rated - Rate this topic

VisualCollection Class

Represents an ordered collection of Visual objects.

System.Object
  System.Windows.Media.VisualCollection

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)
public sealed class VisualCollection : ICollection, 
	IEnumerable

The VisualCollection type exposes the following members.

  Name Description
Public method VisualCollection Initializes a new instance of the VisualCollection class.
Top
  Name Description
Public property Capacity Gets or sets the number of elements that the VisualCollection can contain.
Public property Count Gets the number of elements in the collection.
Public property IsReadOnly Gets a value that indicates whether the VisualCollection is read-only.
Public property IsSynchronized Gets a value that indicates whether access to the VisualCollection is synchronized (thread-safe).
Public property Item Gets or sets the Visual that is stored at the zero-based index of the VisualCollection.
Public property SyncRoot Gets an object that can be used to synchronize access to the VisualCollection.
Top
  Name Description
Public method Add Appends a Visual to the end of the VisualCollection.
Public method Clear Removes all elements from the VisualCollection.
Public method Contains Returns 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.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetEnumerator Retrieves an enumerator that can iterate through the VisualCollection.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method IndexOf Returns the zero-based index of the Visual.
Public method Insert Inserts an element into the VisualCollection at the specified index.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Remove Removes the specified Visual object from the VisualCollection.
Public method RemoveAt Removes the visual object at the specified index in the VisualCollection.
Public method RemoveRange Removes a range of visual objects from the VisualCollection.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top
  Name Description
Public Extension Method AsParallel Enables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension Method AsQueryable Converts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension Method Cast<TResult> Converts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension Method OfType<TResult> Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top
  Name Description
Explicit interface implemetation Private method IEnumerable.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.
Top

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


Note Note

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

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ