Application.ResourceManagerRequested Event

Definition

Occurs during startup of a new WinUI thread to let you provide a custom IResourceManager implementation to be used by the framework for resolving resource URIs.

// Register
event_token ResourceManagerRequested(TypedEventHandler<IInspectable, ResourceManagerRequestedEventArgs const&> const& handler) const;

// Revoke with event_token
void ResourceManagerRequested(event_token const* cookie) const;

// Revoke with event_revoker
Application::ResourceManagerRequested_revoker ResourceManagerRequested(auto_revoke_t, TypedEventHandler<IInspectable, ResourceManagerRequestedEventArgs const&> const& handler) const;
public event TypedEventHandler<object,ResourceManagerRequestedEventArgs> ResourceManagerRequested;
function onResourceManagerRequested(eventArgs) { /* Your code */ }
application.addEventListener("resourcemanagerrequested", onResourceManagerRequested);
application.removeEventListener("resourcemanagerrequested", onResourceManagerRequested);
- or -
application.onresourcemanagerrequested = onResourceManagerRequested;
Public Custom Event ResourceManagerRequested As TypedEventHandler(Of Object, ResourceManagerRequestedEventArgs) 

Event Type

Remarks

The WinUI framework instantiates an MRT Core ResourceManager to resolve resource URIs. For more info, see Manage resources with MRT Core. If your app needs non-standard behavior not provided by the default ResourceManager in order to resolve a particular resource URI, you can provide your own custom implementation of the IResourceManager interface to use instead of the default ResourceManager.

Handle the ResourceManagerRequested event to provide the WinUI framework with a custom IResourceManager to replace the default ResourceManager that the framework creates. In the event handler, instantiate your custom IResourceManager and assign it to the ResourceManagerRequestedEventArgs.CustomResourceManager property. The value of this property is initially null, and it is only checked by the framework once per event raise after all registered event handlers have been invoked. If the property value is still null, then the framework will use the default ResourceManager.

This event is raised once per WinUI thread during initialization. If you use the same IResourceManager for multiple threads, then the IResourceManager must be thread-safe.

We recommend that you register the event handler in the App class constructor so that it is available during initial app launch, as shown here.

public App()
{
   this.InitializeComponent();

   ResourceManagerRequested += (_, e) =>
   {
      // CreateResourceManager() is a custom method you
      // create that returns an instance of IResourceManager.
      IResourceManager resourceManager = CreateResourceManager();
      e.ResourceManager = resourceManager;
   };
}

Applies to

See also