VisualCollection 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示一個有序的物件集合 Visual 。
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
- 實作
範例
以下範例說明如何建立 a VisualCollection 並新增成員。
// 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
完整範例請參見 使用 DrawingVisuals 範例的命中測試。
備註
A VisualCollection 具有隱含的情境親和力。 如果程序嘗試從與擁有 ContainerVisual的上下文不同的情況下存取 ,VisualCollection則會拋出例外。
建構函式
| 名稱 | Description |
|---|---|
| VisualCollection(Visual) |
初始化 VisualCollection 類別的新執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| Capacity |
取得或設定 可以 VisualCollection 包含的元素數量。 |
| Count |
取得集合中的項目數目。 |
| IsReadOnly |
會得到一個值,表示 是否 VisualCollection 為唯讀。 |
| IsSynchronized |
會獲得一個值,指示存取是否 VisualCollection 同步(執行緒安全)。 |
| Item[Int32] |
取得或設定 Visual ,該 儲存在 的零基索引 VisualCollection上。 |
| SyncRoot |
取得一個物件,可用來同步存取 VisualCollection。 |
方法
| 名稱 | Description |
|---|---|
| Add(Visual) |
在 的末VisualCollection尾加上 aVisual。 |
| Clear() |
移除所有元素。VisualCollection |
| Contains(Visual) | |
| CopyTo(Array, Int32) |
將集合中的項目從特定陣列索引開始複製到陣列。 |
| CopyTo(Visual[], Int32) |
將目前的集合複製到傳遞 Visual 的陣列中。 |
| Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
| GetEnumerator() |
取得一個能夠遍歷 的列舉子。VisualCollection |
| GetHashCode() |
做為預設哈希函式。 (繼承來源 Object) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| IndexOf(Visual) |
回傳 的 Visual零基索引。 |
| Insert(Int32, Visual) |
在指定的索引處插入一個元素 VisualCollection 。 |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| Remove(Visual) |
從 中移除指定的Visual物件。VisualCollection |
| RemoveAt(Int32) |
移除指定索引 VisualCollection處的視覺物件。 |
| RemoveRange(Int32, Int32) |
從 中移除一系列視覺物件。VisualCollection |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |
明確介面實作
| 名稱 | Description |
|---|---|
| IEnumerable.GetEnumerator() |
此成員支援 WPF 基礎設施,並非直接從您的程式碼中使用。 關於此成員的描述,請參見 GetEnumerator()。 |
擴充方法
| 名稱 | Description |
|---|---|
| AsParallel(IEnumerable) |
啟用查詢的平行處理。 |
| AsQueryable(IEnumerable) |
將 IEnumerable 轉換成 IQueryable。 |
| Cast<TResult>(IEnumerable) |
將 IEnumerable 的項目轉換成指定的型別。 |
| OfType<TResult>(IEnumerable) |
根據指定的型別篩選 IEnumerable 的專案。 |