VisualCollection VisualCollection VisualCollection VisualCollection Class

Definition

Represents an ordered collection of Visual objects.

public ref class VisualCollection sealed : System::Collections::ICollection
public sealed class VisualCollection : System.Collections.ICollection
type VisualCollection = class
    interface ICollection
    interface IEnumerable
Public NotInheritable Class VisualCollection
Implements ICollection
Inheritance
VisualCollectionVisualCollectionVisualCollectionVisualCollection
Implements

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

Note

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

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.

Constructors

VisualCollection(Visual) VisualCollection(Visual) VisualCollection(Visual) VisualCollection(Visual)

Initializes a new instance of the VisualCollection class.

Properties

Capacity Capacity Capacity Capacity

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

Count Count Count Count

Gets the number of elements in the collection.

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

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

IsSynchronized IsSynchronized IsSynchronized IsSynchronized

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

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

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

SyncRoot SyncRoot SyncRoot SyncRoot

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

Methods

Add(Visual) Add(Visual) Add(Visual) Add(Visual)

Appends a Visual to the end of the VisualCollection.

Clear() Clear() Clear() Clear()

Removes all elements from the VisualCollection.

Contains(Visual) Contains(Visual) Contains(Visual) Contains(Visual)

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

CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32)

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

CopyTo(Visual[], Int32) CopyTo(Visual[], Int32) CopyTo(Visual[], Int32) CopyTo(Visual[], Int32)

Copies the current collection into the passed Visual array.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Retrieves an enumerator that can iterate through the VisualCollection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
IndexOf(Visual) IndexOf(Visual) IndexOf(Visual) IndexOf(Visual)

Returns the zero-based index of the Visual.

Insert(Int32, Visual) Insert(Int32, Visual) Insert(Int32, Visual) Insert(Int32, Visual)

Inserts an element into the VisualCollection at the specified index.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(Visual) Remove(Visual) Remove(Visual) Remove(Visual)

Removes the specified Visual object from the VisualCollection.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

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

RemoveRange(Int32, Int32) RemoveRange(Int32, Int32) RemoveRange(Int32, Int32) RemoveRange(Int32, Int32)

Removes a range of visual objects from the VisualCollection.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() 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().

Extension Methods

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to