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
實作

備註

這個類別會針對 WPF 對 XAML 的處理方式執行內建 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. 它也支援建立 XAML 名稱範圍, 方法是由 WPF 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 , 在和FrameworkElement FrameworkContentElement上公開的方法, 會更適當地呼叫以根據 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. FrameworkElement Name 所公開的屬性較適合用來將初始名稱設定為標記FrameworkContentElement屬性的屬性。The 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類別中使用 API, 只有在您要取代或擴充基底專案行為, 以瞭解其如何處理 xaml 頁面根項目的 xaml 名稱範圍, 以及做為範本的一部分 (使用其他的 XAML 名稱範圍與其余的頁面)。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 的淺層複本 (Shallow Copy)。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 NameScope 中移除名稱/物件對應。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>)

根據輸入 DataTable 物件 (其中泛型參數 TDataRow) 傳回包含 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)

根據輸入 DataRow 物件 (其中泛型參數 TDataTable),將 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)

根據輸入 DataRow 物件 (其中泛型參數 TDataTable),將 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.

適用於

另請參閱