NameScope Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Implements base WPF support for the INameScope methods that store or retrieve name-object mappings into a particular XAML namescope. 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 ICollection<KeyValuePair<string, obj>>
interface seq<KeyValuePair<string, obj>>
interface IEnumerable
interface IDictionary<string, obj>
interface INameScope
interface INameScopeDictionary
Public Class NameScope
Implements ICollection(Of KeyValuePair(Of String, Object)), IDictionary(Of String, Object), IEnumerable(Of KeyValuePair(Of String, Object)), INameScopeDictionary
- Inheritance
-
NameScope
- Implements
-
ICollection<KeyValuePair<String,Object>> ICollection<KeyValuePair<TKey,TValue>> IDictionary<String,Object> IEnumerable<KeyValuePair<String,Object>> IEnumerable<KeyValuePair<TKey,TValue>> IEnumerable<T> IEnumerable INameScope INameScopeDictionary
Remarks
This class implements built-in XAML namescope support for WPF treatment of XAML. NameScope assists in creation of initial XAML namescopes based on parsing XAML, such as when instantiating styles and templates. 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 is generally more devoted to supplying infrastructure than for common user code scenarios that involve working with a XAML namescope. 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. The Name properties exposed by FrameworkElement and FrameworkContentElement are more appropriate properties to use to set the initial name as markup attributes.
The various methods of NameScope are used by base elements and other classes that maintain XAML namescopes in order to support RegisterName and FindName. 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).
In .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.
For more information on XAML namescope concepts, see WPF XAML Namescopes.
Names in a XAML namescope must use a particular grammar that restricts the strings you might use for inputs of NameScope API. See XamlName Grammar.
Constructors
| Name | Description |
|---|---|
| NameScope() |
Initializes a new instance of the NameScope class. |
Fields
| Name | Description |
|---|---|
| NameScopeProperty |
Identifies the NameScope attached property. |
Properties
| Name | Description |
|---|---|
| Count |
Returns the number of items in the collection of mapped names in this NameScope. |
| IsReadOnly |
Gets a value indicating whether the collection is read-only. |
| Item[String] |
Gets or sets the item with the specified key. |
| Keys |
Gets a collection of the keys in the NameScope dictionary. |
| Values |
Gets a collection of the values in the NameScope dictionary. |
Attached Properties
| Name | Description |
|---|---|
| NameScope |
Gets or sets dynamically attached NameScope instances. |
Methods
| Name | Description |
|---|---|
| Add(KeyValuePair<String,Object>) |
Adds an item to the collection. |
| Add(String, Object) |
Adds an item to the collection. |
| Clear() |
Removes all items from the collection. |
| Contains(KeyValuePair<String,Object>) |
Determines whether the collection contains a specified item. |
| ContainsKey(String) |
Returns whether a provided name already exists in this NameScope. |
| CopyTo(KeyValuePair<String,Object>[], Int32) |
Copies the elements of the collection to an array, starting at a particular array index. |
| FindName(String) |
Returns the corresponding object in the XAML namescope maintained by this NameScope, based on a provided name string. |
| GetNameScope(DependencyObject) |
Provides the attached property get accessor for the NameScope attached property. |
| RegisterName(String, Object) |
Registers a new name-object pair into the current XAML namescope. |
| Remove(KeyValuePair<String,Object>) |
Removes the specific object from the collection. |
| Remove(String) |
Removes a mapping for a specified name from the collection. |
| SetNameScope(DependencyObject, INameScope) |
Provides the attached property set accessor for the NameScope attached property. |
| TryGetValue(String, Object) |
Gets the value associated with the specified key. |
| UnregisterName(String) |
Removes a name-object mapping from the XAML namescope. |
Explicit Interface Implementations
| Name | Description |
|---|---|
| IEnumerable.GetEnumerator() |
Returns an enumerator that iterates through a collection. |
| IEnumerable<KeyValuePair<String,Object>>.GetEnumerator() |
Returns an enumerator that iterates through a collection. |