Represents a service that reports situational object-property relationships for markup extension evaluation.
Assembly: System.Xaml (in System.Xaml.dll)
Thetype exposes the following members.
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 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 Type Converters and Markup Extensions for XAML and Service Contexts Available to Type Converters and Markup Extensions.
For markup extensions specifically, a scenario where 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 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.
Although the API name might imply an association with 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:
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 use information 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, is in the System.Xaml assembly. For more information, see Types Migrated from WPF to System.Xaml.
WPF Usage Notes
This service supports framework features such as binding on a dependency property.
In WPF, the service represented by can return objects and properties for situations where the value to return from a markup extension or type converter depends on context.
is leveraged heavily in the internal implementation of BindingBase, the class that implements the binding mechanism for dependency properties in WPF.
A default internal service provider for WPF implements 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 IXamlTypeResolver services, and that is an advanced scenario that is not described here.
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.
Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.