ContentPropertyAttribute 類別
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指出類型的哪一個屬性是 XAML 內容屬性。 XAML 處理器會在處理屬性化類型之 XAML 表示的 XAML 子項目時,使用這項資訊。
public ref class ContentPropertyAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
public sealed class ContentPropertyAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=true)>]
type ContentPropertyAttribute = class
inherit Attribute
Public NotInheritable Class ContentPropertyAttribute
Inherits Attribute
- 繼承
- 屬性
下列範例會建立名為 Film
且已套用 的 ContentPropertyAttribute 類別。 名為 Title
的屬性會以內容屬性表示。
[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 相關聯屬性不是 類型 string
或 object
,則 XAML 處理器會嘗試識別值轉換技術。 第一個檢查是原生類型轉換,可能是 XAML 語言基本類型或該特定 XAML 寫入器實作所啟用的特定原生轉換。 下一個步驟是尋找類型轉換器。 在 .NET 實作中,會根據 TypeConverterAttribute 套用的成員層級或類型層級定義來識別類型轉換器。 如果無法識別任何值轉換,XAML 物件寫入器通常會擲回例外狀況。
若要接受多個單一物件專案做為內容,XAML 內容屬性的類型必須可做為集合類型支援。
Inherited=true
由於屬性的宣告,ContentPropertyAttribute一般會將內容屬性指定套用至所有衍生類別的值。 套用空白 ContentPropertyAttribute 可讓衍生類別移除基類屬性的宣告 (,並請注意類別沒有內容屬性) 。 以不同的方式套用名為 ContentPropertyAttribute 的 ,會以新名稱取代繼承 ContentPropertyAttribute 的 。
在舊版的 .NET Framework 中,這個類別存在於 WPF 特定的元件 WindowsBase 中,而且在 Windows Communication Foundation (WCF) 中也有平行實作。 從 .NET Framework 4.0 開始,ContentPropertyAttribute位於 System.Xaml 元件中。 如需詳細資訊,請參閱 Types Migrated from WPF to System.Xaml。
Windows Presentation Foundation (WPF) 中使用 ContentPropertyAttribute 的 類別範例是 ContentControl,類別Button繼承自此類別。 屬性 ContentControl.Content 是由 所設定 ContentPropertyAttribute的內容屬性。 Button如果在 XAML 中具現化 ,Content的 Button 將會設定為開始和結束按鈕標記之間的專案。
Content |
初始化 ContentPropertyAttribute 類別的新執行個體。 |
Content |
使用指定的名稱,初始化 ContentPropertyAttribute 類別的新執行個體。 |
Equals(Object) |
傳回值,這個值指出此執行個體是否與指定的物件相等。 (繼承來源 Attribute) |
Get |
傳回這個執行個體的雜湊碼。 (繼承來源 Attribute) |
Get |
取得目前執行個體的 Type。 (繼承來源 Object) |
Is |
在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。 (繼承來源 Attribute) |
Match(Object) |
在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。 (繼承來源 Attribute) |
Memberwise |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
To |
傳回代表目前物件的字串。 (繼承來源 Object) |
_Attribute. |
將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。 (繼承來源 Attribute) |
_Attribute. |
擷取物件的類型資訊,可以用來取得介面的類型資訊。 (繼承來源 Attribute) |
_Attribute. |
擷取物件提供的類型資訊介面數目 (0 或 1)。 (繼承來源 Attribute) |
_Attribute. |
提供物件所公開的屬性和方法的存取權。 (繼承來源 Attribute) |
產品 | 版本 |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9, 10 |