Represents a service that reports situational object-property relationships for markup extension evaluation.
Assembly: System.Xaml (in System.Xaml.dll)
represents a service that reports information regarding the object-property structure surrounding where a value converter is invoked.
Type converters and markup extensions can query for Type Converters and Markup Extensions for XAML and Service Contexts Available to Type Converters and Markup Extensions.as a service on the service context that is provided by a XAML object writer, when the XAML object writer invokes value conversion behavior. For more information, see
For markup extensions specifically, a scenario where TargetObject and make sure that object supports your deferral technique. If so, your markup extension returns a value, and if not, your markup extension throws an exception that will be picked up as an inner exception by a XAML object writer. A similar scenario is assuring that a particular property supports a capability, by checking type system characteristics of the TargetProperty.is useful is to determine the validity of your markup extension's situational usage. For example, your markup extension might implement a value deferral mechanism, but using that mechanism might only be appropriate if the target object is capable of using other components of your deferral mechanism at run time. You could check the type system characteristics of the object returned as
Although the API name MarkupExtension::ProvideValue, the information reported by can also be useful to a TypeConverter or ValueSerializer. A TypeConverter or ValueSerializer typically have more context than a markup extension because they are dedicated to a particular target type or target property, and thus the situational validity is usually predictable in the type system. However, other scenarios exist. The following is a list of some scenarios that might be implemented by either a type converter or a markup extension:might imply an association with
Get TargetObject to read instance values of other properties on that object. Note that your handling here might need to be robust for unset values, because the processing order of XAML members on the target object can be nondeterministic.
Get TargetObject to read type-level metadata, or to verify that required interfaces are implemented by the type.
Get TargetProperty to read property metadata.
One scenario is to useinformation to limit which objects or properties are permitted to be set by your markup extension.
Before attempting to use the service, make sure that the service itself is not null when returned by the relevant service provider parameter you are using for context.
When using the service, it is particularly important not to modify the object referenced by the TargetObject property, or other objects referenced by that object. For WPF specifically, these changes could cause unexpected changes that would invalidate the WPF property system.
Do not use the type of TargetProperty to determine which precise type a markup extension or type converter should return. That is not a best practice. Your return type should be consistent with attributing (MarkupExtensionReturnTypeAttribute for markup extensions) or patterns (class name of the type converter).
In previous versions of the .NET Framework, this interface existed in the WPF-specific assembly WindowsBase. In .NET Framework 4, Types Migrated from WPF to System.Xaml.is in the System.Xaml assembly. For more information, see
This service supports framework features such as binding on a dependency property.
In WPF, the service represented bycan return objects and properties for situations where the value to return from a markup extension or type converter depends on context.
BindingBase, the class that implements the binding mechanism for dependency properties in WPF.is leveraged heavily in the internal implementation of
A default internal service provider for WPF implements IXamlTypeResolver services, and that is an advanced scenario that is not described here.for usage by a custom markup extension or type converter. The object and property reported by can only be set by the internal WPF service. Going beyond this definition of how operates would require defining your own service provider for markup extension and type converter usages that implements at the very least the and
A null value for TargetProperty or TargetObject does not necessarily mean that a markup extension or type converter cannot act, although that depends on your implementation. An example case where the values from are null even if the service is available is if your markup extension is nested within another markup extension, such as a Binding. An implementation that relies on should always check for null values if only for the purpose of throwing a specific exception, if that is your intended design.
Available since 3.0
Available since 5.0