DynamicXaml.WinUI 1.0.0

dotnet add package DynamicXaml.WinUI --version 1.0.0
                    
NuGet\Install-Package DynamicXaml.WinUI -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DynamicXaml.WinUI" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DynamicXaml.WinUI" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DynamicXaml.WinUI" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DynamicXaml.WinUI --version 1.0.0
                    
#r "nuget: DynamicXaml.WinUI, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DynamicXaml.WinUI@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DynamicXaml.WinUI&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DynamicXaml.WinUI&version=1.0.0
                    
Install as a Cake Tool

DynamicXAML

DynamicXaml is a library that allows you to dynamically load XAML resources (such as XAML/XBF files embedded inside PRI files) at runtime in UWP and WinUI 3 applications.

With DynamicXaml you can dynamically load external XAML libraries at runtime, which is useful for scenarios like plugin systems, theming, or modular applications where you want to load UI components that aren't part of the application itself nor compiled with it.

Installation

NuGet packages are coming soon, for now you can clone the repository and build the solution to get the library.

Usage

On libraries side

Libraries have to be either native Windows Runtime Components or .NET Class Libraries.

Libraries should add the following property to their project (e.g. csproj, vcxproj, ...) file:

<DisableEmbeddedXbf>false</DisableEmbeddedXbf>

This property will ensure that all XAML resources are embedded into the library's PRI file, which is required for DynamicXaml to work.

Additional considerations for UWP libraries

These considerations are only applicable to UWP libraries and only to manual usages of ms-appx:/// URIs, they do NOT apply to WinUI 3 libraries nor code generated by Xaml Compiler.

If the library is manually accessing its resources via ms-appx:/// URIs, these should be changed to include the library's PRI index name after the second slash like the following example:


<ResourceDictionary Source="ms-appx:///My.Dynamic.Lib/Themes/Generic.xaml" />

<ResourceDictionary Source="ms-appx://My.Dynamic.Lib/My.Dynamic.Lib/Themes/Generic.xaml" />

This limitation exists because Windows.UI.Xaml (aka UWP XAML) uses a private MRM API to load these resources and DynamicXaml aims to avoid using or hooking any private APIs by default, this limitation however does NOT exist in WinUI 3 since it uses a public API (the WinRT MRT Core API) for loading these resources and DynamicXaml hooks that API and makes the required redirections for it to work.

However the library includes an opt-in feature to automatically handle and redirect these URIs at runtime without manual edits, this feature can be enabled by setting the DynamicLoader.EnableUnsafeHooks property to true before loading any PRI files.

Enabling this feature (EnableUnsafeHooks) will cause the library to use and hook private APIs, and despite these private APIs never changed before, it's still not 100% guaranteed that this will stay the same in the future, which may lead to unexpected behavior or crashes if the private APIs change in future Windows versions, use it at your own risk.

On application side

To use DynamicXaml in your application, you need to add a reference to the library and then after initializing XAML, call DynamicLoader.LoadPri with a PRI file StorageFile, on WinUI 3 there's also an overload that accepts a path to the PRI file and a Try variant of the LoadPri function.

Example usage in C#:

using DynamicXaml;

...

// Load the PRI file
StorageFile priFile = await ApplicationData.Current.LocalFolder.GetFileAsync("My.Dynamic.Lib.pri");
DynamicLoader.LoadPri(priFile);

Then you can load the library dll and use the XAML resources defined in it, this is done via either NativeLibrary.Load (C#) or LoadLibrary (Native) in case of native libraries, or Assembly.Load in case of .NET libraries, in case of native libraries you can activate the XAML classes defined in it by calling the DllGetActivationFactory function exported by the dll.

There are sample projects in the repository that demonstrate how to use DynamicXaml for both Native and .NET libraries in both UWP and WinUI 3 applications.

Product Compatible and additional computed target framework versions.
.NET net8.0-windows10.0.19041 is compatible.  net9.0-windows was computed.  net10.0-windows was computed. 
native native is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 117 7/29/2025

Initial release.