NameScope NameScope NameScope NameScope Class

定义

实现对 INameScope 方法的基本 WPF 支持,这些方法用于向特定 XAML 名称范围中存储名称-对象映射或检索此类映射。Implements base WPF support for the INameScope methods that store or retrieve name-object mappings into a particular XAML namescope. 添加附加属性支持,以便更简单地在元素级别动态获取或设置 XAML 名称范围的名称。Adds attached property support to make it simpler to get or set XAML namescope names dynamically at the element level.

public ref class NameScope : System::Collections::Generic::ICollection<System::Collections::Generic::KeyValuePair<System::String ^, System::Object ^>>, System::Collections::Generic::IDictionary<System::String ^, System::Object ^>, System::Collections::Generic::IEnumerable<System::Collections::Generic::KeyValuePair<System::String ^, System::Object ^>>, System::Windows::Markup::INameScopeDictionary
public class NameScope : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string,object>>, System.Collections.Generic.IDictionary<string,object>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string,object>>, System.Windows.Markup.INameScopeDictionary
type NameScope = class
    interface INameScopeDictionary
    interface INameScope
    interface IDictionary<string, obj>
    interface ICollection<KeyValuePair<string, obj>>
    interface seq<KeyValuePair<string, obj>>
    interface IEnumerable
Public Class NameScope
Implements ICollection(Of KeyValuePair(Of String, Object)), IDictionary(Of String, Object), IEnumerable(Of KeyValuePair(Of String, Object)), INameScopeDictionary
继承
NameScopeNameScopeNameScopeNameScope
实现

注解

此类为 XAML 的 WPF 处理实现内置的 XAML 名称范围支持。This class implements built-in XAML namescope support for WPF treatment of XAML. NameScope有助于根据分析 XAML (如实例化样式和模板时)创建初始 XAML 名称范围。NameScope assists in creation of initial XAML namescopes based on parsing XAML, such as when instantiating styles and templates. 它还支持由 WPF XAML 处理器实现的常规 XAML 加载之外发生的进程创建 XAML 名称范围。It also supports creation of XAML namescopes by processes that occur outside of normal XAML loading of elements by the WPF XAML processor implementation.

NameScope通常比涉及使用 XAML 名称范围的常见用户代码方案更专门提供基础结构。NameScope is generally more devoted to supplying infrastructure than for common user code scenarios that involve working with a XAML namescope. 在大多数情况下, FindName在和FrameworkContentElementFrameworkElement公开的方法更适合用于按 XAML 定义的名称搜索元素的方法。For most scenarios, the FindName methods exposed on FrameworkElement and FrameworkContentElement are more appropriate methods to call to search for elements by XAML-defined name. Name 公开FrameworkContentElement的属性是更适合用于将初始名称设置为标记特性的属性。 FrameworkElementThe Name properties exposed by FrameworkElement and FrameworkContentElement are more appropriate properties to use to set the initial name as markup attributes.

的各种方法NameScope由基元素和其他类使用,这些类用于维护 XAML 名称范围以便支持RegisterNameFindNameThe various methods of NameScope are used by base elements and other classes that maintain XAML namescopes in order to support RegisterName and FindName. 通常,仅当你要为NameScope xaml 页面的根元素处理 xaml 名称范围的方法,并将其作为模板的一部分(使用其余 XAML 名称范围与其余的 xaml 名称范围不同)时,才在类中使用该 API。页)。You generally use the API in the NameScope class only if you are replacing or augmenting the base element behavior for how they process XAML namescopes for root elements of a XAML page, and as part of templates (which use a separate XAML namescope from the rest of the page).

.NET Framework 4.NET Framework 4NameScope ,提供了集合接口实现,以便可以访问由 XAML 名称范围保存的名称集合,包括通过对方法的Add调用添加到该集合。In .NET Framework 4.NET Framework 4, NameScope provides collection interface implementations such that you can access the collections of names that are held by a XAML namescope, including adding to it through calls to an Add method.

有关 XAML 名称范围概念的详细信息,请参阅WPF XAML 名称范围For more information on XAML namescope concepts, see WPF XAML Namescopes.

XAML 名称范围中的名称必须使用特定的语法来限制可用于NameScope API 输入的字符串。Names in a XAML namescope must use a particular grammar that restricts the strings you might use for inputs of NameScope API. 请参阅XamlName 语法See XamlName Grammar.

构造函数

NameScope() NameScope() NameScope() NameScope()

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

字段

NameScopeProperty NameScopeProperty NameScopeProperty NameScopeProperty

标识 NameScope 附加属性。Identifies the NameScope attached property.

属性

Count Count Count Count

返回此 NameScope 中映射名称的集合中的项数。Returns the number of items in the collection of mapped names in this NameScope.

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

获取一个值,该值指示集合是否为只读。Gets a value indicating whether the collection is read-only.

Item[String] Item[String] Item[String] Item[String]

获取或设置具有指定键的项。Gets or sets the item with the specified key.

Keys Keys Keys Keys

获取 NameScope 字典中键的集合。Gets a collection of the keys in the NameScope dictionary.

Values Values Values Values

获取 NameScope 字典中值的集合。Gets a collection of the values in the NameScope dictionary.

附加属性

NameScope NameScope NameScope NameScope

获取或设置动态附加的 NameScope 实例。Gets or sets dynamically attached NameScope instances.

方法

Add(KeyValuePair<String,Object>) Add(KeyValuePair<String,Object>) Add(KeyValuePair<String,Object>) Add(KeyValuePair<String,Object>)

向集合中添加一项。Adds an item to the collection.

Add(String, Object) Add(String, Object) Add(String, Object) Add(String, Object)

向集合中添加一项。Adds an item to the collection.

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

从集合中移除所有项。Removes all items from the collection.

Contains(KeyValuePair<String,Object>) Contains(KeyValuePair<String,Object>) Contains(KeyValuePair<String,Object>) Contains(KeyValuePair<String,Object>)

确定集合是否包含指定的项。Determines whether the collection contains a specified item.

ContainsKey(String) ContainsKey(String) ContainsKey(String) ContainsKey(String)

返回此 NameScope 中是否已存在所提供的名称。Returns whether a provided name already exists in this NameScope.

CopyTo(KeyValuePair<String,Object>[], Int32) CopyTo(KeyValuePair<String,Object>[], Int32) CopyTo(KeyValuePair<String,Object>[], Int32) CopyTo(KeyValuePair<String,Object>[], Int32)

从特定的数组索引开始,将集合的元素复制到数组中。Copies the elements of the collection to an array, starting at a particular array index.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
FindName(String) FindName(String) FindName(String) FindName(String)

根据提供的名称字符串,返回由此 NameScope 保留的 XAML 名称范围中的相应对象。Returns the corresponding object in the XAML namescope maintained by this NameScope, based on a provided name string.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetNameScope(DependencyObject) GetNameScope(DependencyObject) GetNameScope(DependencyObject) GetNameScope(DependencyObject)

NameScope 附加属性提供附加属性 get 访问器。Provides the attached property get accessor for the NameScope attached property.

GetType() GetType() GetType() GetType()

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

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
RegisterName(String, Object) RegisterName(String, Object) RegisterName(String, Object) RegisterName(String, Object)

将新的名称-对象对注册到当前的 XAML 名称范围中。Registers a new name-object pair into the current XAML namescope.

Remove(KeyValuePair<String,Object>) Remove(KeyValuePair<String,Object>) Remove(KeyValuePair<String,Object>) Remove(KeyValuePair<String,Object>)

从集合中移除特定对象。Removes the specific object from the collection.

Remove(String) Remove(String) Remove(String) Remove(String)

从集合中移除指定名称的映射。Removes a mapping for a specified name from the collection.

SetNameScope(DependencyObject, INameScope) SetNameScope(DependencyObject, INameScope) SetNameScope(DependencyObject, INameScope) SetNameScope(DependencyObject, INameScope)

NameScope 附加属性提供附加属性 set 访问器。Provides the attached property set accessor for the NameScope attached property.

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

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)
TryGetValue(String, Object) TryGetValue(String, Object) TryGetValue(String, Object) TryGetValue(String, Object)

获取与指定键关联的值。Gets the value associated with the specified key.

UnregisterName(String) UnregisterName(String) UnregisterName(String) UnregisterName(String)

从 XAML 名称范围中删除名称对象映射。Removes a name-object mapping from the XAML namescope.

显式界面实现

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

返回循环访问集合的枚举数。Returns an enumerator that iterates through a collection.

IEnumerable<KeyValuePair<String,Object>>.GetEnumerator() IEnumerable<KeyValuePair<String,Object>>.GetEnumerator() IEnumerable<KeyValuePair<String,Object>>.GetEnumerator() IEnumerable<KeyValuePair<String,Object>>.GetEnumerator()

返回循环访问集合的枚举数。Returns an enumerator that iterates through a collection.

扩展方法

Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue)
TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue)
CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>)

在给定其泛型参数 TDataTable 的输入 DataRow 对象的情况下,返回包含 IEnumerable<T> 对象副本的 DataRowReturns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

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)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>)

返回元素集合,其中包含源集合中每个节点的上级。Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName)

返回经过筛选的元素集合,其中包含源集合中每个节点的上级。Returns a filtered collection of elements that contains the ancestors of every node in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子代节点的集合。Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>)

返回元素集合,其中包含源集合中每个元素和文档的子代元素。Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName)

返回经过筛选的元素集合,其中包含源集合中每个元素和文档的子代元素。Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>)

返回源集合中每个元素和文档的子元素的集合。Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName)

返回源集合中经过筛选的每个元素和文档的子元素集合。Returns a filtered collection of the child elements of every element and document in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>)

返回节点集合(其中包含源集合中的所有节点),并按文档顺序排列。Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子节点集合。Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>)

将源集合中的每个节点从其父节点中移除。Removes every node in the source collection from its parent node.

适用于

另请参阅