XFEExtension.NetCore.WinUIHelper
2.0.0
dotnet add package XFEExtension.NetCore.WinUIHelper --version 2.0.0
NuGet\Install-Package XFEExtension.NetCore.WinUIHelper -Version 2.0.0
<PackageReference Include="XFEExtension.NetCore.WinUIHelper" Version="2.0.0" />
<PackageVersion Include="XFEExtension.NetCore.WinUIHelper" Version="2.0.0" />
<PackageReference Include="XFEExtension.NetCore.WinUIHelper" />
paket add XFEExtension.NetCore.WinUIHelper --version 2.0.0
#r "nuget: XFEExtension.NetCore.WinUIHelper, 2.0.0"
#:package XFEExtension.NetCore.WinUIHelper@2.0.0
#addin nuget:?package=XFEExtension.NetCore.WinUIHelper&version=2.0.0
#tool nuget:?package=XFEExtension.NetCore.WinUIHelper&version=2.0.0
XFEExtension.NetCore.WinUIHelper
📖 中文文档
A WinUI 3 extension library based on .NET 8, providing a set of convenient helper classes, services, and extension methods to streamline WinUI 3 application development.
Table of Contents
Features
- Lightweight IoC Container: Built-in
ServiceManagersupporting service registration and global singleton retrieval. - Navigation Management: Wraps
NavigationViewandFrameto provide a ViewModel-driven navigation experience. - UI Interaction Services: Offers
DialogService,MessageService(similar to InfoBar),LoadingService, and other common interaction services. - MVVM Support: Provides
ObservableObjectextensions and a general-purpose ViewModel base class.
Quick Start
1. Initialization
Initialize in App.xaml.cs, including page registration and exception handling setup.
public App()
{
this.InitializeComponent();
// Set application theme
AppThemeHelper.Theme = ElementTheme.Dark;
// Register navigation pages (PageManager)
// All pages navigable by string or type must be registered here
PageManager.RegisterPage(typeof(AppShellPage));
PageManager.RegisterPage(typeof(MainPage));
PageManager.RegisterPage(typeof(TestPage));
// Global exception handling (optional)
UnhandledException += App_UnhandledException;
}
private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
{
// Display error using the message service
if (ServiceManager.GetService<IMessageService>() is IMessageService messageService)
{
messageService.ShowMessage(e.Message, "An error occurred", InfoBarSeverity.Error);
e.Handled = true;
}
}
2. Build the Shell Page
Create a Shell page (e.g. AppShellPage) containing a NavigationView and bind the relevant services.
AppShellPageViewModel.cs:
public class AppShellPageViewModel : ObservableObject
{
// Use GetService to obtain a service instance
public INavigationViewService NavigationViewService { get; set; } = ServiceManager.GetService<INavigationViewService>();
public IMessageService MessageService { get; set; } = ServiceManager.GetService<IMessageService>();
public ILoadingService LoadingService { get; set; } = ServiceManager.GetService<ILoadingService>();
}
AppShellPage.xaml.cs:
public sealed partial class AppShellPage : Page
{
public AppShellPageViewModel ViewModel { get; set; } = new();
public AppShellPage()
{
Current = this;
this.InitializeComponent();
// 1. Initialize navigation service (bind NavigationView and Frame)
ViewModel.NavigationViewService.Initialize(navigationView, navigationFrame);
// 2. Initialize message service (bind the StackPanel used to display messages)
ViewModel.MessageService.Initialize(messageStackPanel, DispatcherQueue);
// 3. Initialize loading service (bind loading controls)
ViewModel.LoadingService.Initialize(loadingGrid, globalLoadingGrid, globalLoadingTextBlock, DispatcherQueue, ViewModel.NavigationViewService.NavigationService);
// 4. Initial navigation
ViewModel.NavigationViewService.NavigateTo<MainPage>();
}
}
3. Using Services
In a child page's ViewModel (e.g. MainPage), use ServiceManager.GetGlobalService<T>() to retrieve the global service instance that was initialized in the Shell page.
public partial class MainPageViewModel : ObservableObject
{
// Retrieve global instances (use GetGlobalService)
public INavigationViewService? NavigationViewService { get; } = ServiceManager.GetGlobalService<INavigationViewService>();
public IMessageService? MessageService { get; } = ServiceManager.GetGlobalService<IMessageService>();
[RelayCommand]
void DoSomething()
{
// Show a message
MessageService?.ShowMessage("Operation successful!", "Info", InfoBarSeverity.Success);
// Navigate to another page
NavigationViewService?.NavigateTo<TestPage>("parameter to pass");
}
}
Core Features
ServiceManager
A simple dependency injection and service locator.
GetService<T>(): Gets a service instance. If the type follows the naming convention (e.g.IMyService→MyService), an instance is created automatically.GetGlobalService<T>(): Gets a registered global singleton service. Services inheriting fromGlobalServiceBaseautomatically register themselves as global singletons when instantiated (e.g. during Shell page initialization).
Navigation Service
Manages NavigationView selection state and Frame page transition synchronization via INavigationViewService.
Initialize(...): Must be called before use to bind UI elements.NavigateTo<TPage>(parameter): Navigates to the specified page.NavigationService.CanGoBack: Checks whether back navigation is available.
Messages and Dialogs
- IMessageService: Displays non-blocking notifications in a designated area of the UI. Requires a
StackPanelcontainer placed in the Shell page's XAML. - IDialogService: Displays content dialogs.
- ILoadingService: Manages loading states, supporting both page-level overlays and global overlays.
Utility Classes
- PageManager: A static class used to register page types so the navigation system can locate them by
Type. - AppThemeHelper: Manages the application theme (Light / Dark / System).
- NavigationHelper: Provides methods such as
SetParameterfor passing parameters between pages.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows10.0.19041 is compatible. |
-
net10.0-windows10.0.19041
- CommunityToolkit.Mvvm (>= 8.4.2)
- Microsoft.Windows.SDK.BuildTools (>= 10.0.28000.1839)
- Microsoft.WindowsAppSDK (>= 2.0.1)
- XFEExtension.NetCore (>= 4.2.3)
- XFEExtension.NetCore.AutoPath (>= 1.0.1)
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 |
|---|---|---|
| 2.0.0 | 32 | 5/7/2026 |
| 1.2.5 | 116 | 3/13/2026 |
| 1.2.4 | 228 | 11/26/2025 |
| 1.2.3 | 167 | 10/4/2025 |
| 1.2.2 | 216 | 6/22/2025 |
| 1.2.1 | 217 | 5/28/2025 |
| 1.2.0 | 169 | 5/2/2025 |
| 1.1.2 | 173 | 5/2/2025 |
| 1.1.1 | 197 | 4/25/2025 |
| 1.1.0 | 198 | 4/25/2025 |
| 1.0.7 | 244 | 4/8/2025 |
| 1.0.6 | 238 | 4/6/2025 |
| 1.0.5 | 218 | 4/6/2025 |
| 1.0.4 | 203 | 4/6/2025 |
| 1.0.3 | 222 | 4/6/2025 |
| 1.0.2 | 210 | 4/6/2025 |
| 1.0.1 | 208 | 4/6/2025 |
| 1.0.0 | 219 | 4/6/2025 |
目前已正式升级至.NET 10.0