VisualCollection 类

定义

表示 Visual 对象的有序集合。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
继承
VisualCollection
实现

示例

下面的示例演示如何创建VisualCollection并向其添加成员。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

备注

有关完整示例, 请参阅使用 drawingvisuals 进行的命中测试示例For the complete sample, see Hit Test Using DrawingVisuals Sample.

注解

具有VisualCollection隐含的上下文关联。A VisualCollection has implied context affinity. 如果过程尝试VisualCollection从不同于所属ContainerVisual上下文的上下文中访问, 则会引发异常。If a procedure attempts to access the VisualCollection from a different context than the context of the owning ContainerVisual, an exception is thrown.

构造函数

VisualCollection(Visual)

初始化 VisualCollection 类的新实例。Initializes a new instance of the VisualCollection class.

属性

Capacity

获取或设置 VisualCollection 可包含的元素数。Gets or sets the number of elements that the VisualCollection can contain.

Count

获取集合中的元素数。Gets the number of elements in the collection.

IsReadOnly

获取一个值,该值指示 VisualCollection 是否为只读。Gets a value that indicates whether the VisualCollection is read-only.

IsSynchronized

获取一个值,该值指示是否同步对 VisualCollection 的访问(线程安全)。Gets a value that indicates whether access to the VisualCollection is synchronized (thread-safe).

Item[Int32]

获取或设置 Visual,它存储在 VisualCollection 的从零开始的索引处。Gets or sets the Visual that is stored at the zero-based index of the VisualCollection.

SyncRoot

获取可用于同步对 VisualCollection 的访问的对象。Gets an object that can be used to synchronize access to the VisualCollection.

方法

Add(Visual)

Visual 追加到 VisualCollection 的末尾。Appends a Visual to the end of the VisualCollection.

Clear()

VisualCollection 中移除所有元素。Removes all elements from the VisualCollection.

Contains(Visual)

返回一个 Boolean 值,该值指示集合中是否包含指定的 VisualReturns a Boolean value that indicates whether the specified Visual is contained in the collection.

CopyTo(Array, Int32)

从特定的数组索引开始,将集合中的项复制到数组中。Copies the items in the collection to an array, starting at a specific array index.

CopyTo(Visual[], Int32)

将当前集合复制到传递的 Visual 数组中。Copies the current collection into the passed Visual array.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetEnumerator()

检索可循环访问 VisualCollection 的枚举数。Retrieves an enumerator that can iterate through the VisualCollection.

GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IndexOf(Visual)

返回 Visual 的从零开始的索引。Returns the zero-based index of the Visual.

Insert(Int32, Visual)

将元素插入 VisualCollection 的指定索引处。Inserts an element into the VisualCollection at the specified index.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
Remove(Visual)

Visual 中移除指定的 VisualCollection 对象。Removes the specified Visual object from the VisualCollection.

RemoveAt(Int32)

VisualCollection 中指定的索引处移除可视对象。Removes the visual object at the specified index in the VisualCollection.

RemoveRange(Int32, Int32)

VisualCollection 中移除一系列可视对象。Removes a range of visual objects from the VisualCollection.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

显式界面实现

IEnumerable.GetEnumerator()

此成员支持 WPFWPF 基础结构,但不能在代码中直接使用。This member supports the WPFWPF infrastructure and is not intended to be used directly from your code. 有关此成员的说明,请参见 GetEnumerator()For a description of this member, see GetEnumerator().

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于