ContentPropertyAttribute ContentPropertyAttribute ContentPropertyAttribute ContentPropertyAttribute Class

定義

指出類型的哪一個屬性是 XAML 內容屬性。Indicates which property of a type is the XAML content property. XAML 處理器會在處理屬性化類型之 XAML 表示的 XAML 子項目時,使用這項資訊。A XAML processor uses this information when processing XAML child elements of XAML representations of the attributed type.

public ref class ContentPropertyAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
public sealed class ContentPropertyAttribute : Attribute
type ContentPropertyAttribute = class
    inherit Attribute
Public NotInheritable Class ContentPropertyAttribute
Inherits Attribute
繼承
ContentPropertyAttributeContentPropertyAttributeContentPropertyAttributeContentPropertyAttribute
屬性

範例

下列範例會建立名為Film且已套用的ContentPropertyAttribute類別。The following example creates a class named Film that has a ContentPropertyAttribute applied. Title為的屬性會表示為 content 屬性。The property named Title is indicated as the content property.

[ContentProperty("Title")]
public class Film
{
    public Film()
    {
    }

    public string Title
    {
        get { return _title; }
        set { _title = value; }
    }

    private string _title;
}
<ContentProperty("Title")>
Public Class Film
	Public Sub New()
	End Sub

	Public Property Title() As String
		Get
			Return _title
		End Get
		Set(ByVal value As String)
			_title = value
		End Set
	End Property

	Private _title As String
End Class

備註

如果的相關聯屬性ContentPropertyAttribute不是或object類型string , XAML 處理器會嘗試識別值轉換技術。If the associated property of a ContentPropertyAttribute is not of type string or object, a XAML processor attempts to identify a value conversion technique. 第一個檢查適用于原生類型轉換, 這可能是 XAML 語言基本專案, 或是特定 XAML 寫入器執行所啟用的特定原生轉換。The first check is for native type conversion, either of the XAML language primitives or of specific native conversions enabled by that particular XAML writer implementation. 下一個步驟是尋找類型轉換器。The next step is to look for a type converter. 在 .net 的執行中, 會根據所套用的成員TypeConverterAttribute層級或類型層級定義來識別類型轉換器。In the .NET implementations, a type converter is identified based on TypeConverterAttribute on either the member level or type level definition that applies. 如果無法識別值轉換, XAML 物件寫入器通常會擲回例外狀況。If no value conversion can be identified, a XAML object writer typically throws an exception.

為了接受一個以上的物件元素做為內容, XAML 內容屬性的類型必須是可支援的集合類型。In order to accept more than a single object element as content, the type of the XAML content property must be supportable as a collection type.

由於屬性的宣告, 的值ContentPropertyAttribute通常也會將內容屬性指定套用至所有衍生的類別。 Inherited=trueBecause of the Inherited=true declaration of the attribute, a value for a ContentPropertyAttribute normally applies a content property designation to all derived classes as well. 套用空ContentPropertyAttribute的可讓衍生類別透過基類移除 content 屬性屬性的宣告 (並注意類別沒有內容屬性)。Applying an empty ContentPropertyAttribute enables a derived class to remove a declaration of a content property attribute by a base class (and to note that the class has no content property). 套用以不同方式ContentPropertyAttribute命名的, ContentPropertyAttribute會將繼承的取代為新的。Applying a differently named ContentPropertyAttribute replaces the inherited ContentPropertyAttribute with the new one.

在舊版的 .NET Framework 中, 這個類別會存在於 WPF 特定的元件 WindowsBase 中, 而且也具有 Windows Communication Foundation (WCF) 中的平行執行。In previous versions of the .NET Framework, this class existed in the WPF-specific assembly WindowsBase, and also had a parallel implementation in Windows Communication Foundation (WCF). 從 .NET Framework 4.0 開始, ContentPropertyAttribute位於 system.object 元件中。Starting with the .NET Framework 4.0, ContentPropertyAttribute 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

Windows Presentation Foundation (WPF) 中使用的ContentPropertyAttribute類別範例是ContentControl, Button類別繼承自。An example of a class in Windows Presentation Foundation (WPF) that uses the ContentPropertyAttribute is ContentControl, which the Button class inherits from. 屬性是由設定的 content 屬性。 ContentPropertyAttribute ContentControl.ContentThe ContentControl.Content property is the content property set by the ContentPropertyAttribute. 如果是在 XAML 中具現化Content , Button的將會設定為在開始和結束按鈕標記之間的元素。 ButtonIf a Button is instantiated in XAML, the Content of the Button will be set to the element that is between the start and end button tags.

建構函式

ContentPropertyAttribute() ContentPropertyAttribute() ContentPropertyAttribute() ContentPropertyAttribute()

初始化 ContentPropertyAttribute 類別的新執行個體。Initializes a new instance of the ContentPropertyAttribute class.

ContentPropertyAttribute(String) ContentPropertyAttribute(String) ContentPropertyAttribute(String) ContentPropertyAttribute(String)

使用指定的名稱,初始化 ContentPropertyAttribute 類別的新執行個體。Initializes a new instance of the ContentPropertyAttribute class, by using the specified name.

屬性

Name Name Name Name

取得內容屬性之屬性的名稱。Gets the name of the property that is the content property.

TypeId TypeId TypeId TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

傳回值,這個值指出此執行個體是否與指定的物件相等。Returns a value that indicates whether this instance is equal to a specified object.

(Inherited from Attribute)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

(Inherited from Attribute)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)
Match(Object) Match(Object) Match(Object) Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

明確介面實作

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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

適用於

另請參閱