DynamicXaml.WinUI
1.0.0
dotnet add package DynamicXaml.WinUI --version 1.0.0
NuGet\Install-Package DynamicXaml.WinUI -Version 1.0.0
<PackageReference Include="DynamicXaml.WinUI" Version="1.0.0" />
<PackageVersion Include="DynamicXaml.WinUI" Version="1.0.0" />
<PackageReference Include="DynamicXaml.WinUI" />
paket add DynamicXaml.WinUI --version 1.0.0
#r "nuget: DynamicXaml.WinUI, 1.0.0"
#:package DynamicXaml.WinUI@1.0.0
#addin nuget:?package=DynamicXaml.WinUI&version=1.0.0
#tool nuget:?package=DynamicXaml.WinUI&version=1.0.0
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 | Versions 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. |
-
native 0.0
- No dependencies.
-
net8.0-windows10.0.19041
- Microsoft.WindowsAppSDK (>= 1.6.241114003)
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.