BetterWinUI.PageActivation 0.2.0-alpha.1

This is a prerelease version of BetterWinUI.PageActivation.
dotnet add package BetterWinUI.PageActivation --version 0.2.0-alpha.1
                    
NuGet\Install-Package BetterWinUI.PageActivation -Version 0.2.0-alpha.1
                    
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="BetterWinUI.PageActivation" Version="0.2.0-alpha.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BetterWinUI.PageActivation" Version="0.2.0-alpha.1" />
                    
Directory.Packages.props
<PackageReference Include="BetterWinUI.PageActivation" />
                    
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 BetterWinUI.PageActivation --version 0.2.0-alpha.1
                    
#r "nuget: BetterWinUI.PageActivation, 0.2.0-alpha.1"
                    
#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 BetterWinUI.PageActivation@0.2.0-alpha.1
                    
#: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=BetterWinUI.PageActivation&version=0.2.0-alpha.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=BetterWinUI.PageActivation&version=0.2.0-alpha.1&prerelease
                    
Install as a Cake Tool

BetterWinUI.PageActivation

Application-owned Page factories for WinUI, without a DI container or navigation dependency. The package includes the source generator that connects a partial WinUI Application to the XAML metadata activation entry point.

using BetterWinUI.PageActivation;
using Microsoft.UI.Xaml;

[GeneratePageActivationHook]
public sealed partial class App : Application
{
    public App()
    {
        this.UsePageActivation(pageType => pageType == typeof(HomePage)
            ? new HomePage(new HomeViewModel())
            : throw new InvalidOperationException($"No factory for {pageType}."));
        InitializeComponent();
    }
}

The generated method has this contract:

public void UsePageActivation(Func<Type, Microsoft.UI.Xaml.Controls.Page> activate);
  • Register once per Application instance, before the Pages that need the factory are activated. A second registration throws and leaves the first factory in place; a null delegate is rejected.
  • The callback receives the actual requested Page type and must return a non-null, compatible Page. Null results and incompatible types throw InvalidOperationException; factory exceptions propagate.
  • Before installation, activation uses the original XAML activator. After installation, the factory owns Page creation completely. There is no automatic fallback or continuation overload.
  • Frame cache hits reuse existing Pages without invoking the factory. The hook does not intercept direct new Page(...) calls, assign DataContext, or own/dispose factory-created instances.
  • The hook applies to Page activation through the Application's XAML metadata, not only one Frame. It runs synchronously on the activating thread; construct Pages on the XAML thread.
  • The XAML compiler must expose metadata for the Page and the native metadata provider on the App. Installing a factory does not create missing metadata for arbitrary runtime types.

The generator uses Scriban and emits native interface forwarding and WinRT exposure code. It does not use reflection to discover the App's private metadata provider at runtime. The marker assembly targets .NET 8; generated activation code runs in the consuming WinUI application. The generator targets netstandard2.0 and Roslyn 4.8.

For Microsoft DI registration and constructor injection, use BetterWinUI.PageActivation.DependencyInjection.

Diagnostics

BWPH0001

The application must be declared partial.

BWPH0002

The application must be a concrete, non-generic, top-level WinUI Application in a named namespace.

BWPH0003

Only one application per assembly may declare [GeneratePageActivationHook].

BWPH0004

The XAML compiler output is present but the App has no unique supported native metadata provider property.

BWPH0005

A user declaration conflicts with UsePageActivation(Func<Type, Page>). Other overloads are allowed.

BWPH0006

The referenced XAML metadata interfaces cannot support the required activation interception.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on BetterWinUI.PageActivation:

Package Downloads
BetterWinUI.PageActivation.DependencyInjection

NativeAOT-compatible dependency injection activation for WinUI pages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0-alpha.1 69 9/23/2026
0.2.0-alpha.0 57 9/23/2026