XmlnsPrefixAttribute 类

定义

当在 XAML 文件(序列化)中编写元素和特性时,或与具有 XAML 编辑功能的设计环境进行交互时,标识要与 XAML 命名空间关联用于 XAML 的推荐前缀。Identifies a recommended prefix to associate with a XAML namespace for XAML usage, when writing elements and attributes in a XAML file (serialization) or when interacting with a design environment that has XAML editing features.

public ref class XmlnsPrefixAttribute sealed : Attribute
public sealed class XmlnsPrefixAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=true)]
public sealed class XmlnsPrefixAttribute : Attribute
type XmlnsPrefixAttribute = class
    inherit Attribute
Public NotInheritable Class XmlnsPrefixAttribute
Inherits Attribute
继承
XmlnsPrefixAttribute
属性

注解

XAML 处理器或合并了 xaml 的框架或执行 XAML 序列化的任何进程通常应遵循建议的前缀。XAML processors or frameworks that incorporate XAML, or any process that performs XAML serialization, should generally honor the recommended prefix. 在任何情况下,如果原始 XAML 源中特定映射的前缀不是以某种方式保留在运行时对象关系图中,或者由框架或技术存储,则可能需要前缀。The prefix might be necessary in any case where prefixes from specific mappings in the original XAML source are not somehow preserved in the runtime object graph or otherwise stored by a framework or technology. 框架可能具有特定的首选项,说明如何序列化其自己的程序集中忽略建议前缀的类型;这可能是为了一致地升级默认的 XAML 命名空间。A framework might have specific preferences for how to serialize its own types that ignore the recommended prefix from its own assemblies; this might be done to consistently promote a default XAML namespace. 但是,此类框架应还为可能的第三方和其 XAML 类型的工具用法提供建议的前缀。However, such a framework should still provide recommended prefixes for possible third-party and tool usages of its XAML types. 请参阅下面的 "XAML 设计器支持或一般序列化的最佳实践" 部分。See "Best Practice for XAML Designer Support or General Serialization" section below.

前缀的一般建议是使用短字符串,因为前缀通常应用于来自 XAML 命名空间的所有序列化元素。A general recommendation for prefixes is to use short strings, because the prefix is typically applied to all serialized elements that come from the XAML namespace. 前缀字符串长度可能会对序列化的 XAML 输出的大小产生明显影响。The prefix string length can have a noticeable effect on the size of serialized XAML output.

如果请求的前缀已被另一个以前遇到的/序列化的 XAML 命名空间标识符使用,则该行为是未指定的(行为取决于每个 XAML 处理器实现)。If a prefix being requested is already in use by another previously encountered/serialized XAML namespace identifier, the behavior is unspecified (behavior is up to each individual XAML processor implementation).

在大多数情况下,仅当在同一 XAML 命名空间的程序集中至少应用了一个 XmlnsDefinitionAttribute 时,才应用 XmlnsPrefixAttributeIn most cases, you apply XmlnsPrefixAttribute only if you have also applied at least one XmlnsDefinitionAttribute in the assembly for that same XAML namespace.

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

XAML 设计器支持或一般序列化的最佳实践Best Practice for XAML Designer Support or General Serialization

即使您希望关联的 XAML 命名空间在大多数情况下都是框架或库的默认 XAML 命名空间,仍应将非空字符串指定为 XAML 命名空间的建议前缀。Even if you intend the associated XAML namespace to be the default XAML namespace in most usage cases for your framework or library, you should still specify a non-empty string as the recommended prefix for a XAML namespace. 默认的 XAML 命名空间信息会在各个 XAML 文件和 XAML 节点流中携带。Default XAML namespace information is carried in individual XAML files and XAML node streams. 默认的 XAML 命名空间以及在给定的 XAML 源中定义该命名空间的方法,在不使用 XmlnsPrefixAttribute的情况下,可以轻松地为每个 case 序列化永久保留。The default XAML namespace and how it is defined in a given XAML source can easily be perpetuated for per-case serialization without using XmlnsPrefixAttribute. 但是,在 XAML 作者已选择将默认 XAML 命名空间映射到其他内容的情况下,XmlnsPrefixAttribute 非常有用。However, the XmlnsPrefixAttribute is useful for cases where the XAML author has chosen to map the default XAML namespace to something else. 在此方案中,嵌入到设计环境中的 XAML 文本编辑器可以将 XmlnsPrefixAttribute 用作初始 XAML 命名空间 xmlns 映射的提示。In this scenario a XAML text editor embedded in a design environment can use XmlnsPrefixAttribute as a hint for an initial XAML namespace xmlns mapping. 或者,设计环境可以将实时映射添加到后备 XAML 以实现设计的形式,例如将对象拖出工具箱和可视化设计图面。Or a design environment can add just-in-time mappings to the backing XAML for design metaphors such as dragging objects out of a toolbox and into a visual design surface. 而且,设计器也可以同时支持多个启用 XAML 的框架,并且具有依赖于 .NET Framework XAML 服务的常见 XAML 序列化程序,而不是特定于框架的序列化。Also, it is conceivable that a designer could simultaneously support multiple XAML-enabling frameworks, and has a common XAML serializer that relies on .NET Framework XAML Services rather than framework-specific serialization. 如果在设计工具之间交换 XAML,或在 XAML 编辑器与其他使用者(如标记编译器或其他序列化)之间进行往返,则为这些方案指定 XmlnsPrefixAttribute 有助于使类型的 XAML 用法更易于移植且更可靠。Specifying a XmlnsPrefixAttribute for these scenarios helps make the XAML usage for your types more portable and robust if the XAML is exchanged between design tools, or undergoes a round trip between XAML editors and other consumers such as markup compilers or other serialization.

构造函数

XmlnsPrefixAttribute(String, String)

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

属性

Prefix

获取与此特性关联的推荐前缀。Gets the recommended prefix associated with this attribute.

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)
XmlNamespace

获取与此特性关联的 XAML 命名空间标识符。Gets the XAML namespace identifier associated with this attribute.

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

(继承自 Attribute)
GetType()

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

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)
MemberwiseClone()

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

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)

适用于

另请参阅