IAmbientProvider 接口

定义

返回一个服务,该服务可将有关环境属性或环境类型的信息项返回到类型转换器和标记扩展。Represents a service that can return information items about ambient properties or ambient types to type converters and markup extensions.

public interface class IAmbientProvider
public interface IAmbientProvider
type IAmbientProvider = interface
Public Interface IAmbientProvider

注解

此接口表示一种服务, 该服务可帮助类型转换器和标记扩展来获取 XAML 类型系统 (XamlMember对象) 的环境属性标识符。This interface represents the service that can help type converters and markup extensions to get the ambient property identifiers for the XAML type system (XamlMember objects). 服务还可以从类获取环境属性值。The service can also get the ambient property values from classes. 类型也可以是环境;使用该类型作为其值的任何成员都应被视为环境。Types can also be ambient; any member that uses that type as its value should be considered ambient.

此服务通常通过对的调用GetService返回, 这是针对特定于上下文的服务提供程序进行的。This service is typically returned through a call to GetService, which is made against a context-specific service provider. 服务提供程序通常可用于需要它的上下文 (例如, 值转换器的执行代码)。The service provider is generally available to contexts that need it, such as the execution code of a value converter. 有关详细信息, 请参阅可用于类型转换器和标记扩展的 XAML 的类型转换器和标记扩展For more information, see Type Converters and Markup Extensions for XAML and Service Contexts Available to Type Converters and Markup Extensions.

关于环境属性About Ambient Properties

环境属性是一个属性, 它的属性值应该可供类型转换器和标记扩展用法在 XAML 节点结构和从中创建的对象图中。An ambient property is a property whose property value should be available to type converter and markup extension usages that exist in the XAML node structure and in the object graph created from it. 这与在加载路径或保存路径的序列化阶段的对象写入阶段中的 XAML 处理器相关。This is relevant for a XAML processor during the object-writing phase of the load path or the serialization phase of a save path.

在加载路径情况下, 环境属性值可能会影响 XAML 节点结构中存在的其他属性的对象图中的值。In the load path case, the ambient property value might influence the value in the object graph of other properties that exist underneath it in a XAML node structure. 当处理为 XAML 节点流时, 环境概念表示环境属性值必须可用于的类型转换器和标记扩展StartObjectEndObjectWhen processed as a XAML node stream, the ambient concept means the ambient property value must be available to type converters and markup extensions from StartObject to EndObject. 同样, 用于保存路径的类型转换器可以使用环境属性及其值的知识。Similarly, a type converter that is used for the save path can use knowledge of the ambient property and its value. 因此, 生成的 XAML 是更好的往返表示形式。Therefore, the XAML that is produced is a better round-trip representation.

对于常规成员, XAML 不指定对象成员的处理顺序。For members in general, XAML does not specify the order in which members of an object must be processed. 但是, 必须先由 XAML 读取器处理任何环境属性值, 以便其他属性中包含的类型转换器和标记扩展用法可以通过IAmbientProvider服务访问它。However, any ambient property value must be processed first by the XAML reader so that the type converter and markup extension usages that are contained in other properties can access it through the IAmbientProvider service.

DependsOn是一个类似的概念, 也会影响 XAML 节点处理顺序。DependsOn is a similar concept that also influences XAML node-processing order. 但是, DependsOn只能用于对等成员和节点关系, 它无法影响所有后代。However, DependsOn can only be used for peer member and node relationships; it cannot influence all descendants. 同时, DependsOn直接影响对象图的属性设置; 而环境技术依赖于类型转换器或标记扩展。Also, DependsOn directly influences object graph property setting; whereas the ambient technique relies on type converters or markup extensions. 在环境技术中, 还必须有一个指定的类型转换器或标记扩展定义, 指定应如何解释环境属性值并将其应用于对象。In the ambient technique, there must also be a specific type converter or markup extension definition that specifies how the ambient property value should be interpreted and applied to the object.

WPF 用法说明WPF Usage Notes

WPFWPF功能集中阐释的环境属性方案为Style.TargetType, 它可以为其他值限定必需的属性名称查找。An ambient property scenario that is illustrated in the WPFWPF feature set is Style.TargetType, which can qualify the necessary property name lookups for other values. 在这种情况下Style.TargetType , 值Setter.Property限定位于其下的 XAML 节点中的值。In this case, the Style.TargetType value qualifies the Setter.Property values that are located in the XAML nodes underneath it. Setter.Property使用的类型转换器行为DependencyPropertySetter.Property uses the type converter behavior for a DependencyProperty. 此行为通过从可Style.TargetType供类型转换器GetFirstAmbientValue和标记扩展使用的服务上下文进行查询来访问环境值。This behavior accesses the ambient Style.TargetType value by querying GetFirstAmbientValue from a service context that is available to type converters and markup extensions.

WPF 功能集中阐释的环境类型方案为ResourceDictionaryAn ambient type scenario that is illustrated in the WPF feature set is ResourceDictionary. ResourceDictionary具有可包含其他ResourceDictionary要合并的对象的属性,并且合并方案的预期资源解析顺序与加载类型的顺序冲突。MergedDictionariesResourceDictionary has a MergedDictionaries property that can contain other ResourceDictionary objects to merge, and the intended order of resource resolution for the merged scenario clashes with the order that types are loaded. ResourceDictionary适用AmbientAttribute于 XAML 处理器可使用StaticResource使用情况正确处理合并字典中的引用。ResourceDictionary applies AmbientAttribute so that a XAML processor can correctly process the references in a merged dictionary with StaticResource usages. 具体而言StaticResource , 是标记扩展, 它调用GetAllAmbientValuesSpecifically, StaticResource is a markup extension, which calls GetAllAmbientValues.

方法

GetAllAmbientValues(IEnumerable<XamlType>, Boolean, IEnumerable<XamlType>, XamlMember[])

针对所请求的种类和属性集,返回环境属性信息项的可枚举集合。Returns an enumerable set of ambient property information items for the requested set of types and properties.

GetAllAmbientValues(IEnumerable<XamlType>, XamlMember[])

针对所请求的属性集,返回环境属性信息项的可枚举集合。Returns an enumerable set of ambient property information items for the requested set of properties.

GetAllAmbientValues(XamlType[])

针对请求的类型,返回可能的环境类型的对象实例的可枚举集合。Returns an enumerable set of object instances of possible ambient types for the requested types.

GetFirstAmbientValue(IEnumerable<XamlType>, XamlMember[])

从请求的属性集中返回单个环境属性信息项,具体情况视哪个属性是遇到的第一个属性而定。Returns a single ambient property information item from the requested set of properties, based on which property is first encountered.

GetFirstAmbientValue(XamlType[])

返回第一个匹配对象,该对象是所请求类型可能的环境类型。Returns the first matching object that is a possible ambient type for the requested types.

适用于

另请参阅