Regions.WPF
0.0.7-beta
.NET 5.0
This package targets .NET 5.0. The package is compatible with this framework or higher.
.NET Framework 4.6.2
This package targets .NET Framework 4.6.2. The package is compatible with this framework or higher.
Suggested Alternatives
This is a prerelease version of Regions.WPF.
dotnet add package Regions.WPF --version 0.0.7-beta
NuGet\Install-Package Regions.WPF -Version 0.0.7-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.7-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.7-beta" />
<PackageReference Include="Regions.WPF" />
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.7-beta
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Regions.WPF, 0.0.7-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.7-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.7-beta&prerelease
#tool nuget:?package=Regions.WPF&version=0.0.7-beta&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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:每次导航
新建实例,回退后不再持有,重定向导航后页面可被释放。
区域适配
支持多种容器类型的区域适配:可扩展适配 ContentControl、ItemsControl、TabControl 等,注册机制自动关联容器与适配器,满足不同 UI 需求。
src/Regions.WPF/RegionAdapter.cs 是本库的核心组件之一,负责将区域(Region)机制适配到不同类型的容器控件(如 ContentControl、ItemsControl、TabControl 等)。
通过自定义 RegionAdapter,可以让区域管理器灵活支持多种 UI 容器,极大提升了扩展性和兼容性。
快速用法
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
- 可使用
RegionName附加属性声明 Region。
<ContentControl regions:RegionManager.RegionName="MainRegion" />
添加的 Region 可以用 IRegionManager.RemoveRegion / IRegionManager.ClearRegions 手动清理。
- 可使用
AddToRegion附加属性将带有名称的控件添加到指定 Region。
<Grid regions:RegionManager.RegionName="MainRegion">
<Grid regions:RegionManager.AddToRegion="MainRegion,/ContentRegion"
regions:RegionManager.RegionName="ContentRegion" />
</Grid>
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 | Versions 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.
-
.NETFramework 4.6.2
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.8)
- System.ValueTuple (>= 4.5.0)
-
.NETFramework 4.7.2
-
.NETFramework 4.8
-
net5.0-windows7.0
-
net6.0-windows7.0
-
net7.0-windows7.0
-
net8.0-windows7.0
-
net9.0-windows7.0
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.7-beta | 261 | 11/25/2025 |