IQueryAmbient 介面


查詢是否應該將指定的屬性視為目前範圍中的環境屬性。Queries for whether a specified property should be treated as ambient in the current scope.

public interface class IQueryAmbient
public interface IQueryAmbient
type IQueryAmbient = interface
Public Interface IQueryAmbient


環境屬性機制的目的是要藉由通知 XAML 物件寫入器避免將特定物件具現化, 在已知物件是暫時的值而不適用於一般執行時間的情況下, 藉此改善剖析時間應用程式.The purpose of an ambient property mechanism is to improve parsing time by informing a XAML object writer to avoid instantiating certain objects, in cases where it is known that the objects are for values that are temporary and not useful for a typical run time application. 一般來說, 屬性 get 存取子的 XAML 查閱或 XAML 處理需要具現化這類物件, 以使用立即可用的值來填滿物件圖形表示。Normally, XAML lookups or XAML processing of a property get accessor would need to instantiate such objects to fill the object graph representation with ready-to-use values.

IQueryAmbient有一個成員: IsAmbientPropertyAvailableIQueryAmbient has one member: IsAmbientPropertyAvailable.

IQueryAmbient是的平行機制AmbientAttributeIQueryAmbient is a parallel mechanism to AmbientAttribute. IQueryAmbient是可避免使用反映來判斷資訊的特殊機制, 也可以採取動作 situationally (指定的物件可以選擇報告true IsAmbientPropertyAvailablefalse ), 而屬性基本上是靜態的分析)。IQueryAmbient is the specialized mechanism that avoids using reflection to determine information, and can also act situationally (a given object could choose to report true or false for IsAmbientPropertyAvailable), whereas the attribute is essentially static analysis). AmbientAttribute是 XAML 物件寫入器可以使用的一般機制, 而且通常會與專用的 XAML 類型系統屬性IsAmbientIsAmbient相關聯。AmbientAttribute is the general mechanism that can be used by XAML object writers and that typically correlates to the dedicated XAML type system properties IsAmbient and IsAmbient.

IQueryAmbient 的 WPF 執行WPF Implementations of IQueryAmbient

在 WPF 中IQueryAmbient , 是用於資源字典查閱程式。In WPF, IQueryAmbient is used for the resource dictionary lookup process. 查閱程式會取得整個Resources WPF 邏輯樹狀結構中的連續值, 直到找到索引鍵或判斷索引鍵不存在範圍中為止。The lookup process gets successive Resources values throughout the WPF logical tree, working towards the root of the resource scope until either a key is found or the key is determined to not exist in scope. 一般來說, 執行這ResourceDictionary項作業時, 每次都需要具現化, 才能接收結果。Normally, doing so would require instantiating a ResourceDictionary each time to receive the results. 將的內容Resources宣告為環境, Resources只要 exists 就能優化此查閱程式。Declaring the contents of Resources as ambient so long as Resources exists optimizes this lookup process. 在 WPF 中, 此介面會在下列情況中執行:In WPF, this interface is implemented in the following cases:



查詢是否可以將指定的具名屬性視為目前範圍中的環境屬性。Queries for whether a specified named property can be considered ambient in the current scope.