AmbientAttribute 類別

定義

指定應該視為環境的屬性或類型。 環境概念與 XAML 處理器如何判斷成員類別擁有者有關。

public ref class AmbientAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Property, Inherited=true)]
public sealed class AmbientAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method | System.AttributeTargets.Property, Inherited=true)]
public sealed class AmbientAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Property, Inherited=true)>]
type AmbientAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method | System.AttributeTargets.Property, Inherited=true)>]
type AmbientAttribute = class
    inherit Attribute
Public NotInheritable Class AmbientAttribute
Inherits Attribute
繼承
AmbientAttribute
屬性

備註

環境屬性是一個屬性,其中值預期可在剖析器內容中建立物件圖形時使用,但一般類型成員查閱會基於建立的立即 XAML 節點集而暫停。 環境概念有兩個主要案例:

  • 相同物件的一些其他屬性會影響並限定該物件屬性查閱應該如何運作。

  • 屬性代表較大的延遲機制,以及查閱成員值的環境功能會延伸到目前物件中包含的所有物件。

這個屬性可以套用至具有啟用環境屬性查閱行為之預期容器的特定屬性,也可以套用至類別,以在所有屬性的實值型別情況下啟用環境屬性行為。

AmbientAttribute 也可以套用至 CLR 方法,以支援將 XAML 可附加屬性設定為環境。 這是必要的,因為在CLR實作中,XAML 附加屬性會實作/表示為具有 getset 方法的存取子模式來反映。 屬性沒有實際的CLR屬性存在,因此限制的使用AttributeTargetsProperty方式不會啟用將可附加成員指定為環境。 針對您想要報告為環境、屬性存取子的 get 可附加成員。 您不應該嘗試屬性方法,這些方法不是特別支援可附加成員的方法。

在舊版 .NET Framework 中,這個類別存在於 WPF 特定的元件 WindowsBase 中。 在 .NET Framework 4 中,AmbientAttribute位於 System.Xaml 元件中。 如需詳細資訊,請參閱 Types Migrated from WPF to System.Xaml

在類型層級套用的環境類型 (類型 AmbientAttribute ,) 可用於需要依序解析屬性類型的特定 XAML 處理情況。

物件寫入器案例

如果您要定義 XAML 物件寫入器,而且遇到套用的屬性 AmbientAttribute 、方法或類型,您通常必須存取服務,以判斷寫出物件所需的預期環境屬性查閱行為。 如需詳細資訊,請參閱IAmbientProvider

值轉換器

類型轉換子或標記延伸可能需要知道環境資訊,才能處理代表間接類型對應的屬性,例如屬性,這些屬性會以具有或沒有限定資格的字串名稱來指定成員或類型。 在此案例中, AmbientAttribute 不適合直接用於值轉換器程式代碼邏輯。 相反地,值轉換器應該依賴 XAML 寫入器處理行為,這會在呼叫時將其服務內容傳入 IAmbientProvider 您的值轉換器方法。

AmbientAttribute 的 WPF 案例

  • TargetType () 的屬性Style可以限定尋找值中Setter.Property屬性名稱支持參考所需的必要屬性名稱查閱。

  • 屬性內 Resources 的所有內容 () 專案 ResourceDictionary 以及範本內容,應該能夠存取其他對等作為值。 將整個 Resources 屬性宣告為環境叫用邏輯,以在 WPF XAML 剖析器中啟用此功能。

如需在類型層級設定AmbientAttribute的案例範例,請參閱 ResourceDictionary

建構函式

AmbientAttribute()

初始化 AmbientAttribute 類別的新執行個體。

屬性

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,這個值指出此執行個體是否與指定的物件相等。

(繼承來源 Attribute)
GetHashCode()

傳回這個執行個體的雜湊碼。

(繼承來源 Attribute)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱