FrameworkElement.Tag 屬性

定義

取得或設定可以用來儲存關於此元素自訂資訊的任意物件值。Gets or sets an arbitrary object value that can be used to store custom information about this element.

public:
 property System::Object ^ Tag { System::Object ^ get(); void set(System::Object ^ value); };
[System.Windows.Localizability(System.Windows.LocalizationCategory.NeverLocalize)]
public object Tag { get; set; }
[<System.Windows.Localizability(System.Windows.LocalizationCategory.NeverLocalize)>]
member this.Tag : obj with get, set
Public Property Tag As Object

屬性值

Object

所要的值。The intended value. 此屬性沒有預設值。This property has no default value.

屬性

備註

這個屬性類似于其他 Microsoft 程式設計模型中的標記屬性,例如 Visual Basic for Applications 或 Windows Forms。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.

因為這個屬性會接受物件,所以您必須使用屬性專案使用方式,才能將 Tag XAML 中的屬性設定為具有已知和內建類型轉換子之物件以外的任何專案,例如字串。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 的 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

適用於

另請參閱