AmbientAttribute 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定屬性或類型應該視為環境。 環境概念與 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
- 繼承
- 屬性
備註
環境屬性是指在建立物件圖時,該值預期會在解析器上下文中可用,但為了立即建立 XAML 節點集而暫停典型型別成員查詢的屬性。 環境概念主要有兩種情境:
同一物件的其他屬性會影響並限定物件屬性查詢的運作方式。
此特性代表更大規模的延遲機制,查詢成員值的環境功能延伸至目前物件中所有物件。
此屬性可套用於具有預期容器以啟用環境屬性查詢行為的特定屬性,或用於類別,在所有該值類型情況下啟用環境屬性行為。
AmbientAttribute 也可以應用於 CLR 方法,以支援將 XAML 可附加屬性歸因為環境屬性。 這可能是必要的,因為在 CLR 實作中,XAML 附加屬性會以 和 getset 方法的存取器模式實作/表示給反射。 沒有真正的 CLR 屬性屬性,因此限制 的AttributeTargetsProperty使用無法將可附加成員指定為環境。 對於想報告為環境音的可附加成員,請標明該 accessor。get 你不應該試圖歸因於那些不明確支持可連結成員的方法。
在先前版本的 .NET 框架中,此類別存在於 WPF 專用的組合語言 WindowsBase 中。 在 .NET Framework 4 中,是 AmbientAttribute System.Xaml 組合語言。 更多資訊請參閱 「從 WPF 遷移到 System.Xaml」的類型。
環境型別(在 AmbientAttribute 型別層級應用的型別)可用於某些 XAML 處理情境,當屬性型別需要被打亂順序時。
物件撰寫情境
如果你在定義 XAML 物件寫入器,遇到一個屬性、方法或型別,其中 AmbientAttribute 是套用的,通常你必須存取服務來判斷寫出物件所需的環境屬性查詢行為。 如需詳細資訊,請參閱IAmbientProvider。
價值轉換器
型別轉換器或標記擴充可能需要知道環境資訊,才能處理代表間接型別映射的屬性,例如以字串名稱指定成員或型別(有無限定)的屬性。 在此情境下, AmbientAttribute 並不打算直接用於數值轉換碼邏輯。 相反地,值轉換器應依賴 XAML 寫入者的處理行為,當被呼叫時,該行為會在服務上下文中傳遞 IAmbientProvider 給你的值轉換器方法。
AmbientAttribute 的 WPF 情境
屬性StyleTargetType()可符合尋找價值中屬性名稱Setter.Property後盾參考所需的屬性名稱查詢。
屬性內
Resources的所有內容( ResourceDictionary項目)以及範本內容,都應該能以值形式存取其他節點。 將整個Resources屬性宣告為環境屬性,會啟動 WPF XAML 解析器中啟用此功能的邏輯。
請參考 ResourceDictionary 一個在類型層級設定 AmbientAttribute 的範例。
建構函式
| 名稱 | Description |
|---|---|
| AmbientAttribute() |
初始化 AmbientAttribute 類別的新執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| TypeId |
在衍生類別中實作時,取得這個 Attribute的唯一標識碼。 (繼承來源 Attribute) |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
傳回值,這個值表示這個實例是否等於指定的物件。 (繼承來源 Attribute) |
| GetHashCode() |
傳回這個實例的哈希碼。 (繼承來源 Attribute) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| IsDefaultAttribute() |
在衍生類別中覆寫時,指出這個實例的值是否為衍生類別的預設值。 (繼承來源 Attribute) |
| Match(Object) |
在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。 (繼承來源 Attribute) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |
明確介面實作
| 名稱 | Description |
|---|---|
| _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) |