Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

MarkupExtension.ProvideValue Method

When implemented in a derived class, returns an object that is provided as the value of the target property for this markup extension.

Namespace:  System.Windows.Markup
Assembly:  System.Xaml (in System.Xaml.dll)
public abstract Object ProvideValue(
	IServiceProvider serviceProvider
)

Parameters

serviceProvider
Type: System.IServiceProvider

A service provider helper that can provide services for the markup extension.

Return Value

Type: System.Object
The object value to set on the property where the extension is applied.

When a XAML processor processes a type node and member value that is a markup extension, it invokes the ProvideValue method of that markup extension and writes the result into the object graph or serialization stream. The XAML object writer passes service context to each such implementation through the serviceProvider parameter.

See "Notes to Implementers" section for more information on how to implement ProvideValue in a custom markup extension.

WPF Usage Notes

Important noteImportant

WPF classes that have specific interactions with markup set operations should not rely on IReceiveMarkupExtension for a .NET Framework 4 implementation. Use XamlSetMarkupExtensionAttribute-attributed callbacks instead.

Notes to Implementers

Common services returned by the default service provider that is typically available to a custom or existing MarkupExtension implementation include the following primary services.

Potentially, implementations of ProvideValue can ignore the serviceProvider parameter. This is viable for some basic scenarios, where no context at all is required for returning a value.

In typical usage, the .NET Framework XAML Services and the implemented XAML object writers will provide a service provider to all value converter methods that are invoked during XAML processing. However, for robustness, you should provide code paths for null values both for the service provider itself and for any requested service. Null values might occur if your markup extension is applied in a circumstance where the typical service support provided by a XAML processor infrastructure is not available.

For more information on available services from the XAML service provider context and how to use them, see Type Converters and Markup Extensions for XAML.

Implementations that require a certain service to be available in order to produce a useful ProvideValue result are expected to throw exceptions if that service is not available. The recommended exception to throw is InvalidOperationException.

The implementation may also throw exceptions if one of the arguments that the custom markup extension needs in order to provide a value is null, is invalid for its data type, or does not contain a value that the markup extension is capable of processing. The recommended exception to throw is InvalidOperationException.

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.