Custom​Xaml​Resource​Loader Custom​Xaml​Resource​Loader Custom​Xaml​Resource​Loader Custom​Xaml​Resource​Loader Class

Definition

Enables loading of custom resource dictionaries as sources. Override GetResource to provide the logic that a XAML parser can use to look up the necessary resources at load time.

public : class CustomXamlResourceLoader : ICustomXamlResourceLoader, ICustomXamlResourceLoaderOverridespublic class CustomXamlResourceLoader : ICustomXamlResourceLoader, ICustomXamlResourceLoaderOverridesPublic Class CustomXamlResourceLoader Implements ICustomXamlResourceLoader, ICustomXamlResourceLoaderOverrides// This API is not available in Javascript.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

CustomXamlResourceLoader supports a markup extension usage {CustomResource}. This markup extension is unique to the Windows Runtime XAML framework (it did not exist in precursor XAML technologies such as Windows Presentation Foundation (WPF) and Microsoft Silverlight.)

A {CustomResource} usage doesn't work by default (the base implementation of GetResource is incomplete). To make a valid {CustomResource} reference, you must perform each of these steps:

  1. Derive a custom class from CustomXamlResourceLoader and override GetResource method. Do not call base in the implementation.
  2. Set CustomXamlResourceLoader.Current to reference your class in initialization logic. This must happen before any page-level XAML that includes the {CustomResource} extension usage is loaded. One place to set CustomXamlResourceLoader.Current is in the Application subclass constructor that's generated for you in the App.xaml code-behind templates.
  3. Now you can use {CustomResource} extensions in the XAML that your app loads as pages, or from within XAML resource dictionaries.

{CustomResource} markup extension can be used from XAML in a similar way to {StaticResource} markup extension, which performs built-in resource lookup from various ResourceDictionary locations. The difference is that the app itself implements the resource lookup logic for a {CustomResource} markup extension usage by supplying a custom resource loader. To implement the custom resource loader, the application must provide a class that derives from CustomXamlResourceLoader and override the GetResource method. The app must register its custom resource loader by setting the static property CustomXamlResourceLoader.Current to an instance of its custom resource loader class. This registration must be done on a XAML UI thread before any parsing of XAML that uses {CustomResource} markup extension. If the application uses multiple UI threads, a separate registration must be done on each.

The way in which the CustomXamlResourceLoader stores its resources is probably not related to ResourceDictionary at all. Typically, in addition to the required overrides, your CustomXamlResourceLoader class would provide internal or public methods that enable storing, keying and otherwise working with the resource items in an underlying collection.

Constructors

CustomXamlResourceLoader() CustomXamlResourceLoader() CustomXamlResourceLoader() CustomXamlResourceLoader()

Initializes a new instance of the CustomXamlResourceLoader class.

public : CustomXamlResourceLoader()public CustomXamlResourceLoader()Public Sub New()// This API is not available in Javascript.

Properties

Current Current Current Current

Returns the active CustomXamlResourceLoader instance.

public : static CustomXamlResourceLoader Current { get; set; }public static CustomXamlResourceLoader Current { get; set; }Public Static ReadWrite Property Current As CustomXamlResourceLoader// This API is not available in Javascript.

Methods

GetResource(String, String, String, String) GetResource(String, String, String, String) GetResource(String, String, String, String) GetResource(String, String, String, String)

When overridden in a derived class, specifies the logic of resource lookup for this CustomXamlResourceLoader. Given a resource ID and some type information about the expected result, returns the requested resource.

protected : virtual PlatForm::Object GetResource(PlatForm::String resourceId, PlatForm::String objectType, PlatForm::String propertyName, PlatForm::String propertyType)protected virtual object GetResource(String resourceId, String objectType, String propertyName, String propertyType)Protected Overridable Function GetResource(resourceId As String, objectType As String, propertyName As String, propertyType As String) As object// This API is not available in Javascript.
Parameters
resourceId
PlatForm::String String String String

The string-form key of the resource to get.

objectType
PlatForm::String String String String

The expected type of the resource.

propertyName
PlatForm::String String String String

The name of the property that serves as the key in the custom resource lookup logic.

propertyType
PlatForm::String String String String

The type of the property that serves as the key, with type represented as a string.

Returns
PlatForm::Object object object object

The retrieved resource.

Remarks

This method will be called by the Windows Runtime XAML parser whenever it encounters a {CustomResource} markup extension usage in markup. The resourceId comes from the default key markup extension argument to {CustomResource} markup extension, and the other input parameters come from context, such as which property the usage is applied to.

See Also