INameScope 接口

定义

关于如何在特定的 XMAL 名称范围内访问元素的名称,以及如何强制该 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.NET Framework 4INameScope , 为 system.exception 程序集。In .NET Framework 4.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 类NameScope实现。This interface is implemented by the WPF class NameScope. 大多数 XAML 名称范围操作WPFWPF都是通过NameScope使用实例进行操作, 但信息偶尔通过使用INameScope引用进行通信。Most XAML namescope operations in WPFWPF operate by using NameScope instances, but information is occasionally communicated internally by using INameScope references.

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

方法

FindName(String)

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

RegisterName(String, Object)

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

UnregisterName(String)

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

适用于

另请参阅