INameScope 接口


针对如何在特定的 XAML 名称范围内访问元素的名称,以及如何强制该 XAML 名称范围内名称的唯一性,定义一个协定。Defines a contract for how names of elements should be accessed within a particular XAML namescope, and how to enforce uniqueness of names within that XAML namescope.

public interface class INameScope
public interface INameScope
type INameScope = interface
Public Interface INameScope


此接口由具有子元素的类实现,这些子元素旨在通过模板或延迟比喻重复使用。This interface is implemented by classes that have child elements that are intended to be reused through the template or defer metaphor. 模板、工厂和类似构造必须具有唯一的 XAML 名称范围,它们独立于主对象图和根 XAML。Templates, factories and similar constructs must have unique XAML namescopes that are separate from a main object graph and root XAML. 此处的原则是,当从这些子元素创建的对象引入应用程序的对象图时,不应出现名称冲突,因此,依赖于名称标识符的 DOM 操作和 XAML 引用技术可以依赖于每个 XAML 名称范围中的名称唯一性。The principle here is that there should be no name collisions when objects created from those child elements are introduced to an application's object graph, and so that DOM operations and XAML reference techniques that rely on the name identifier can rely on name uniqueness in each XAML namescope.

在 .NET Framework 的以前版本中,此接口存在于 WPF 特定的程序集 WindowsBase 中。In previous versions of the .NET Framework, this interface existed in the WPF-specific assembly WindowsBase. 在 .NET Framework 4 中, INameScope 位于 system.exception 程序集中。In .NET Framework 4, INameScope is in the System.Xaml assembly. 有关详细信息,请参阅 Types Migrated from WPF to System.XamlFor more information, see Types Migrated from WPF to System.Xaml.

WPF 用法说明WPF Usage Notes

此接口由 WPF 类实现 NameScopeThis interface is implemented by the WPF class NameScope. WPF 中的大部分 XAML 名称范围操作都是通过使用实例来运行的 NameScope ,但有时会使用引用在内部进行信息通信 INameScopeMost XAML namescope operations in WPF operate by using NameScope instances, but information is occasionally communicated internally by using INameScope references.

使用工厂或延迟形式与 XAML 表示形式结合使用的 WPF 类的示例包括 StyleFrameworkTemplateExamples of WPF classes that use a factory or defer metaphor combined with XAML representation are Style and FrameworkTemplate. 这些实现通常依赖于类中提供的接口方法的显式版本 NameScopeThese implementations usually rely on the explicit versions of the interface methods available from the NameScope class.



返回具有提供的标识名称的对象。Returns an object that has the provided identifying name.

RegisterName(String, Object)

将提供的名称注册到当前的 XAML 名称范围中。Registers the provided name into the current XAML namescope.


从当前的 XAML 名称范围中注销提供的名称。Unregisters the provided name from the current XAML namescope.