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
                    
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="XFEExtension.NetCore.WinUIHelper" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="XFEExtension.NetCore.WinUIHelper" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="XFEExtension.NetCore.WinUIHelper" />
                    
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 XFEExtension.NetCore.WinUIHelper --version 2.0.0
                    
#r "nuget: XFEExtension.NetCore.WinUIHelper, 2.0.0"
                    
#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 XFEExtension.NetCore.WinUIHelper@2.0.0
                    
#: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=XFEExtension.NetCore.WinUIHelper&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=XFEExtension.NetCore.WinUIHelper&version=2.0.0
                    
Install as a Cake Tool

XFEExtension.NetCore.WinUIHelper

NuGet Version NuGet Downloads License: MIT .NET

📖 中文文档

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 ServiceManager supporting service registration and global singleton retrieval.
  • Navigation Management: Wraps NavigationView and Frame to provide a ViewModel-driven navigation experience.
  • UI Interaction Services: Offers DialogService, MessageService (similar to InfoBar), LoadingService, and other common interaction services.
  • MVVM Support: Provides ObservableObject extensions 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. IMyServiceMyService), an instance is created automatically.
  • GetGlobalService<T>(): Gets a registered global singleton service. Services inheriting from GlobalServiceBase automatically register themselves as global singletons when instantiated (e.g. during Shell page initialization).

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 StackPanel container 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 SetParameter for passing parameters between pages.
Product Compatible and additional computed target framework versions.
.NET net10.0-windows10.0.19041 is compatible. 
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
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