Regions.WPF 0.0.2-beta

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

Regions.NET

一个轻量级、Prism 风格的 WPF 区域(Region)导航框架,支持 DI、导航历史、生命周期事件、redirect 语义等。

特性

  • 支持 WPF XAML 区域声明(propdp)
  • 支持 DI 容器(Microsoft.Extensions.DependencyInjection)自动解析页面
  • 支持导航历史(GoBack/GoForward)
  • 支持 redirect 语义(类比 uniapp 的 redirectTo)
  • 支持 INavigationAware 生命周期事件(OnNavigatedFrom/OnNavigatedTo)
  • 支持页面持有策略(AddSingleton/AddScoped/AddTransient)

页面持有策略说明

  • AddSingleton:页面实例全局唯一,始终持有,即使重定向导航也不会释放。
  • AddScoped:同一区域页面唯一,回退导航/前进导航都能维持页面实例。
  • AddTransient:每次导航新建实例,回退后不再持有,重定向导航后页面可被释放。

快速用法

1. 注册服务

var services = new ServiceCollection();
services.AddSingleton<IRegionManager, RegionManager>();
services.AddSingleton<IRegionNavigationJournal, RegionNavigationJournal>();
services.AddSingleton<IRegionNavigationService, RegionNavigationService>();
services.AddTransient<PageA>(); // 或 AddScoped/AddSingleton
services.AddTransient<PageB>();

2. XAML 声明 Region

<ContentControl regions:RegionManager.RegionName="MainRegion" />

3. 导航页面

// 普通导航
_regionManager.RequestNavigate("MainRegion", new Uri("/PageA", UriKind.Relative));
// 重定向导航
_regionManager.RequestRedirect("MainRegion", new Uri("/PageB", UriKind.Relative));
// 回退导航
_regionManager.RequestGoBack("MainRegion");

4. 页面生命周期

页面或 ViewModel 实现 INavigationAware:

public class PageA : UserControl, INavigationAware
{
   public void OnNavigatedFrom(object? parameter = null) { /* 离开时 */ }
   public void OnNavigatedTo(object? parameter = null) { /* 进入时 */ }
}

适用场景

  • 需要 MVVM/DI/导航解耦的 WPF 应用
  • 需要页面生命周期、导航历史、redirect 等高级导航特性的桌面应用
Product Compatible and additional computed target framework versions.
.NET net5.0-windows7.0 is compatible.  net6.0-windows was computed.  net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net7.0-windows7.0 is compatible.  net8.0-windows was computed.  net8.0-windows7.0 is compatible.  net9.0-windows was computed.  net9.0-windows7.0 is compatible.  net10.0-windows was computed. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 is compatible.  net481 was computed. 
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
0.0.2-beta 126 8/14/2025
0.0.1-beta 116 8/14/2025