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
- 实现
示例
以下示例演示如何创建 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
注释
有关完整示例,请参阅 使用 DrawingVisuals 示例进行命中测试。
注解
具有 VisualCollection 隐式上下文相关性。 如果过程尝试从与拥有ContainerVisual上下文不同的上下文访问VisualCollection,则会引发异常。
构造函数
| 名称 | 说明 |
|---|---|
| VisualCollection(Visual) |
初始化 VisualCollection 类的新实例。 |
属性
| 名称 | 说明 |
|---|---|
| Capacity |
获取或设置可包含的元素 VisualCollection 数。 |
| Count |
获取集合中的元素数。 |
| IsReadOnly |
获取一个值,该值指示是否 VisualCollection 为只读。 |
| IsSynchronized |
获取一个值,该值指示对 VisualCollection 同步的访问是否同步(线程安全)。 |
| Item[Int32] |
获取或设置 Visual 存储在从零开始的索引处的 VisualCollection。 |
| SyncRoot |
获取可用于同步对 . VisualCollection的访问的对象。 |
方法
| 名称 | 说明 |
|---|---|
| Add(Visual) |
将 a Visual 追加到 . 的 VisualCollection末尾。 |
| 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) |
从 VisualCollection. 中删除指定的Visual对象。 |
| RemoveAt(Int32) |
删除位于指定索引处的 VisualCollection视觉对象。 |
| RemoveRange(Int32, Int32) |
从 VisualCollection.. 中删除一系列视觉对象。 |
| ToString() |
返回一个表示当前对象的字符串。 (继承自 Object) |
显式接口实现
| 名称 | 说明 |
|---|---|
| IEnumerable.GetEnumerator() |
此成员支持 WPF 基础结构,不打算直接从代码使用。 有关此成员的说明,请参阅 GetEnumerator()。 |
扩展方法
| 名称 | 说明 |
|---|---|
| AsParallel(IEnumerable) |
启用查询的并行化。 |
| AsQueryable(IEnumerable) |
将 IEnumerable 转换为 IQueryable。 |
| Cast<TResult>(IEnumerable) |
将 IEnumerable 的元素强制转换为指定类型。 |
| OfType<TResult>(IEnumerable) |
根据指定类型筛选 IEnumerable 的元素。 |