Navis.WinUI
0.9.4
See the version list below for details.
dotnet add package Navis.WinUI --version 0.9.4
NuGet\Install-Package Navis.WinUI -Version 0.9.4
<PackageReference Include="Navis.WinUI" Version="0.9.4" />
<PackageVersion Include="Navis.WinUI" Version="0.9.4" />
<PackageReference Include="Navis.WinUI" />
paket add Navis.WinUI --version 0.9.4
#r "nuget: Navis.WinUI, 0.9.4"
#:package Navis.WinUI@0.9.4
#addin nuget:?package=Navis.WinUI&version=0.9.4
#tool nuget:?package=Navis.WinUI&version=0.9.4
Navis.WinUI
Install the NuGet package:
dotnet add package Navis.WinUI
Navis.WinUI is a compact WinUI 3 navigation library for typed, nested, and declarative page navigation.
Quick usage
Register navigation with the application's service collection. INavigation injected while a page is being created is bound to the frame activating that page. When resolved elsewhere, it defers lookup until an operation or property is used, then targets the single loaded, enabled root frame on the calling UI thread.
using Navis.WinUI.Extensions;
services.AddNavisNavigation();
Enable navigation on a Frame and optionally provide its first page. XamlType converts a XAML type name to the Type expected by Navis:
<Page
xmlns:main="using:YourApp.Views"
xmlns:nav="using:Navis.WinUI">
<Frame
nav:NavigationHost.IsEnabled="True"
nav:NavigationHost.InitialPage="{nav:XamlType TypeName=main:HomePage}" />
</Page>
Use the contextual navigation service from a page or view model:
public sealed class HomeViewModel(INavigation navigation)
{
public void OpenDetails() => navigation.Navigate<DetailsPage>();
public void OpenOrder(Order order) =>
navigation.Navigate<DetailsPage, Order>(order);
}
Navigate<TPage>() navigates without a parameter. Navigate<TPage, TParameter>(parameter) passes a strongly typed value to the destination. Both methods also accept a NavigationKind such as Replace or Reset.
Receive a typed parameter and participate in the navigation lifecycle with INavigationAware<TParameter>:
public sealed class DetailsViewModel : INavigationAware<Order>
{
public ValueTask OnNavigatedToAsync(
Order order,
CancellationToken cancellationToken)
{
// Load the order.
return ValueTask.CompletedTask;
}
public ValueTask OnNavigatedFromAsync(CancellationToken cancellationToken) =>
ValueTask.CompletedTask;
}
XAML navigation
Attach navigation to a button or other button-based control. Navigate.To selects the page, Navigate.Kind selects the journal operation, and Navigate.Target selects the current, parent, or root navigation host:
<Button
xmlns:pages="using:YourApp.Views"
xmlns:nav="using:Navis.WinUI"
Content="Open details"
nav:Navigate.To="{nav:XamlType TypeName=pages:DetailsPage}"
nav:Navigate.Kind="Navigate"
nav:Navigate.Target="Current" />
Parameters can be bound in XAML with Navigate.Parameter:
<Button
nav:Navigate.Parameter="{x:Bind ViewModel.SelectedOrder}"
nav:Navigate.To="{nav:XamlType TypeName=pages:DetailsPage}" />
For a detail page, set NavigationViewProperties.OwnerPage to the page represented by its navigation item. The owner item is selected while the detail page is open, including when the item is nested or in the footer:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:nav="using:Navis.WinUI"
xmlns:pages="using:YourApp.Views"
nav:NavigationViewProperties.OwnerPage="{nav:XamlType TypeName=pages:OrdersPage}">
</Page>
Nested frames
Enable navigation on a child Frame inside a page to create a nested host. Parent is the direct host, Child is the current loaded child host, and Root resolves the top-level host. Navigate, CurrentPageType, and NavigateForward stay within the injected host's frame. CanGoBack and NavigateBack search loaded descendants deepest-first, then use the current frame; using Root gives the whole window this back behavior.
To preserve the child page and its journal when the outer frame leaves the container page, cache that page:
<Page
x:Class="YourApp.Views.WorkspacePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:nav="using:Navis.WinUI"
xmlns:pages="using:YourApp.Views"
NavigationCacheMode="Required">
<Frame
nav:NavigationHost.IsEnabled="True"
nav:NavigationHost.InitialPage="{nav:XamlType TypeName=pages:WorkspaceHomePage}" />
</Page>
Attach TitleBarNavigation.IsBackTarget only to the outer frame. Its title bar then reflects child history and invokes the same deepest-first back behavior.
Caveats
INavigationresolved during page activation is bound to that frame. Deferred instances used outside activation require exactly one loaded, enabled root frame on the calling UI thread; zero or multiple roots throw. Deferred instances do not capture a frame, queue operations, or dispatch to another UI thread.- Navigation must run on the frame's UI thread.
- Requests made while another navigation request is in flight are ignored.
- Typed parameters must match the destination's
INavigationAware<TParameter>type at runtime. Navigate.Target="Parent"requires a nested navigation host with a parent frame.Rootresolves the top-level host, so parent/root routing requires the corresponding nested-frame structure.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows10.0.19041 is compatible. |
-
net10.0-windows10.0.19041
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.11)
- Microsoft.Windows.SDK.BuildTools (>= 10.0.28000.2526)
- Microsoft.WindowsAppSDK (>= 2.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.