VisualCollection Класс
Определение
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, которое указывает, содержится ли в коллекции указанный Visual.Returns 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() |
Возвращает объект Type для текущего экземпляра.Gets 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() |
Возвращает строку, представляющую текущий объект.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 в объект IQueryable.Converts an IEnumerable to an IQueryable. |