VisualCollection VisualCollection VisualCollection VisualCollection Class

定義

代表 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
繼承
VisualCollectionVisualCollectionVisualCollectionVisualCollection
實作

範例

下列範例示範如何建立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.

備註

AVisualCollection具有隱含內容親和性。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(Visual) VisualCollection(Visual) VisualCollection(Visual)

初始化 VisualCollection 類別的新執行個體。Initializes a new instance of the VisualCollection class.

屬性

Capacity Capacity Capacity Capacity

取得或設定 VisualCollection 可包含的項目數目。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

取得值,這個值表示 VisualCollection 是否為唯讀。Gets a value that indicates whether the VisualCollection is read-only.

IsSynchronized IsSynchronized IsSynchronized IsSynchronized

取得值,指出 VisualCollection 的存取是否同步 (安全執行緒)。Gets a value that indicates whether access to the VisualCollection is synchronized (thread-safe).

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

取得或設定 Visual,這個項目儲存在 VisualCollection 的索引位置 (以零為起始)。Gets or sets the Visual that is stored at the zero-based index of the VisualCollection.

SyncRoot SyncRoot SyncRoot SyncRoot

取得可用以同步存取 VisualCollection 的物件。Gets an object that can be used to synchronize access to the VisualCollection.

方法

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

Visual 附加至 VisualCollection 的結尾。Appends a Visual to the end of the VisualCollection.

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

移除 VisualCollection 中的所有項目。Removes all elements from the VisualCollection.

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

傳回 Boolean 值,表示集合中是否包含指定的 VisualReturns 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)

將目前集合複製至傳遞的 Visual 陣列。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()

擷取可以逐一查看 VisualCollection 的列舉值。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()

取得目前執行個體的 TypeGets the Type of the current instance.

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

傳回 Visual 的以零起始的索引。Returns the zero-based index of the Visual.

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

將項目插入至 VisualCollection 中指定的索引位置。Inserts an element into the VisualCollection at the specified index.

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

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

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

Visual 移除指定的 VisualCollection 物件。Removes the specified Visual object from the VisualCollection.

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

移除 VisualCollection 中所指定索引處的視覺物件。Removes the visual object at the specified index in the VisualCollection.

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

VisualCollection 移除某範圍的視覺物件。Removes a range of visual objects from the VisualCollection.

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

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

明確介面實作

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

Extension Methods

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

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

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

根據指定的型別來篩選 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)

將轉換IEnumerableIQueryableConverts an IEnumerable to an IQueryable.

適用於