FrameworkElement.Tag 属性


获取或设置任意对象值,该值可用于存储关于此元素的自定义信息。Gets or sets an arbitrary object value that can be used to store custom information about this element.

 property System::Object ^ Tag { System::Object ^ get(); void set(System::Object ^ value); };
public object Tag { get; set; }
member this.Tag : obj with get, set
Public Property Tag As Object



预期值。The intended value. 此属性没有默认值。This property has no default value.



此属性类似于其他 Microsoft 编程模型中的标记属性,如 Visual Basic for Applications 或 Windows 窗体。This property is analogous to Tag properties in other Microsoft programming models, such as Visual Basic for Applications or Windows Forms. Tag 旨在提供预先存在的属性位置,你可以在其中存储有关任何 FrameworkElement 的一些基本自定义信息,而无需为元素划分子类。Tag is intended to provide a pre-existing property location where you can store some basic custom information about any FrameworkElement without requiring you to subclass an element.

由于此属性采用对象,因此需要使用属性元素用法,以便将 XAML 中的 Tag 属性设置为具有已知的内置类型转换器的对象(如字符串)以外的任何对象。Because this property takes an object, you need to use the property element usage in order to set the Tag property in XAML to anything other than an object with a known and built-in type converter, such as a string. 以这种方式使用的对象通常不在标准 WPF 命名空间中,因此可能需要将命名空间映射到外部命名空间才能作为 XAML 元素引入。Objects used in this manner are typically not within the standard WPF namespaces and therefore may require namespace mapping to the external namespace in order to be introduced as XAML elements. 有关详细信息,请参阅WPF xaml 的 Xaml 命名空间和命名空间映射Wpf 的自定义类For details, see XAML Namespaces and Namespace Mapping for WPF XAML and XAML and Custom Classes for WPF.

依赖项属性信息Dependency Property Information

标识符字段Identifier field TagProperty
元数据属性设置为 trueMetadata properties set to true None