StaticResourceExtension.ProvideValue(IServiceProvider) 方法


傳回物件,這個物件應該設定於套用這個延伸的屬性上。Returns an object that should be set on the property where this extension is applied. 對於 StaticResourceExtension,這是在資源字典中找到的物件,其中要尋找的物件是以 ResourceKey 識別。For StaticResourceExtension, this is the object found in a resource dictionary, where the object to find is identified by the ResourceKey.

 override System::Object ^ ProvideValue(IServiceProvider ^ serviceProvider);
public override object ProvideValue (IServiceProvider serviceProvider);
override this.ProvideValue : IServiceProvider -> obj
Public Overrides Function ProvideValue (serviceProvider As IServiceProvider) As Object



可以為標記延伸提供服務的物件。Object that can provide services for the markup extension.



要在屬性上設定的物件值,標記延伸提供的值會在這個屬性中進行評估。The object value to set on the property where the markup extension provided value is evaluated.


serviceProvidernull,或無法實作必要的服務。serviceProvider was null, or failed to implement a required service.


這個方法支援 WPFWPF XAML 處理器的實作為,但不能直接呼叫。This method supports WPFWPF XAML processor implementation, and is not intended to be called directly. XAML 處理器執行會使用這個方法, StaticResource 在建立物件期間適當地處理延伸模組值。The XAML processor implementation uses this method for proper handling of StaticResource extension values during object creation.

要設定的屬性可透過 (的標準屬性來識別, PropertyInfo) 或 DependencyProperty (相依性屬性) 。The property to be set can be identified by a PropertyInfo (standard property) or DependencyProperty (dependency property).

這種執行會依賴 XAML 相關的服務,並以傳遞的為基礎 serviceProviderThis implementation relies on XAML-related services based on the passed serviceProvider. 不得為 nullIt must not be null. .NET Framework 4.NET Framework 4 執行中,以下是服務內容所需的服務:In the .NET Framework 4.NET Framework 4 implementation, the following are required services from service context:

如果缺少這些服務中的任何一項,則使用標記延伸會擲回例外狀況。If any of these services are missing, usage of the markup extension throws an exception.