NuExt.Minimal.Mvvm.MahApps.Metro integrates MahApps.Metro with NuExt.Minimal.Mvvm.Wpf. It provides scoped MahApps dialog coordination, Metro dialogs through the common IAsyncDialogService contract, and document management for MetroTabControl using the existing NuExt ViewModel and document lifecycles.
- Scoped dialog coordination — use the native
IDialogCoordinatorAPI through a Window-aware UI service. - Unified dialog contract — show custom Metro dialogs through
IAsyncDialogServicewith View resolution, ViewModel initialization, validation, cancellation, and deterministic cleanup. - Metro tabbed documents — host Views and ViewModels in
MetroTabControlthrough the commonIAsyncDocumentManagerServicecontract. - Shared lifecycle — reuse the same parent, parameter, initialization, closing, and disposal model as
NuExt.Minimal.Mvvm.Wpf. - Native API access — use MahApps-specific dialogs directly when the common NuExt abstraction is not sufficient.
Add the MahApps theme and the integration package resources to App.xaml, then use MetroWindow as the base for your main window. See the MahApps.Metro Quick Start.
<!-- App.xaml -->
<Application ...>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/NuExt.Minimal.Mvvm.MahApps.Metro;component/Themes/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application><!-- MainWindow.xaml -->
<mah:MetroWindow
x:Class="MyApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
Title="MyApp" Width="900" Height="600"
WindowStartupLocation="CenterScreen">
<!-- content -->
</mah:MetroWindow><!-- attach the MahApps-backed dialog service on a window -->
<nx:Interaction.Behaviors xmlns:nx="http://schemas.nuext.minimal/xaml">
<nx:DialogCoordinatorService x:Name="DialogCoordinatorService"/>
<nx:MetroDialogService x:Name="Dialogs"
DialogCoordinator="{Binding Source={x:Reference DialogCoordinatorService}}" />
</nx:Interaction.Behaviors>// ViewModel (NuExt.Minimal.Mvvm.Wpf base)
private IAsyncDialogService Dialogs => GetRequiredService<IAsyncDialogService>("Dialogs");
public async Task AskAsync(CancellationToken ct)
{
await using var viewModel = new ConfirmViewModel();
var result = await Dialogs.ShowDialogAsync(
MessageBoxButton.OKCancel,
title: "Confirm",
documentType: "MyDialogView",
viewModel: viewModel,
parentViewModel: this,
parameter: null,
cancellationToken: ct);
if (result != MessageBoxResult.OK) return;
// proceed...
}Use the native MahApps API when a built-in input, message, login, or progress dialog is more appropriate:
private IDialogCoordinator DialogCoordinator => GetRequiredService<IDialogCoordinator>();
var result = await DialogCoordinator.ShowMessageAsync(
this,
"Confirmation",
"Continue?",
MessageDialogStyle.AffirmativeAndNegative); <mah:MetroTabControl>
<nx:Interaction.Behaviors xmlns:nx="http://schemas.nuext.minimal/xaml">
<nx:MetroTabbedDocumentService x:Name="Tabs" CloseButtonEnabled="True"
ActiveDocument="{Binding ActiveDocument}"
FallbackViewType="{x:Type views:ErrorView}">
</nx:MetroTabbedDocumentService>
</nx:Interaction.Behaviors>
</mah:MetroTabControl>private IAsyncDocumentManagerService Tabs => GetRequiredService<IAsyncDocumentManagerService>("Tabs");
public async Task OpenCustomerAsync(CustomerModel model, CancellationToken ct)
{
var doc = await Tabs.FindDocumentByIdOrCreateAsync(
id: model.Id,
documentType: "CustomerView",
viewModelFactory: () => new CustomerViewModel(model),
parentViewModel: this,
parameter: null,
cancellationToken: ct);
doc.Show();
}See the repo samples/MetroWpfApp for a runnable example.
- WPF on .NET 8/9/10/11 and .NET Framework 4.6.2+
- MahApps.Metro 3
MetroWindowfor MahApps dialog hostingMetroTabControlfor Metro tabbed documents
Via NuGet:
dotnet add package NuExt.Minimal.Mvvm.MahApps.MetroOr via Visual Studio:
- Go to
Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution.... - Search for
NuExt.Minimal.Mvvm.MahApps.Metro. - Click "Install".
NuExt.Minimal.Mvvm.SourceGeneratorremoves ViewModel boilerplate at compile time.
- NuExt.Minimal.Mvvm
- NuExt.Minimal.Mvvm.SourceGenerator
- NuExt.Minimal.Behaviors.Wpf
- NuExt.Presentation.Wpf
- NuExt.Minimal.Mvvm.Wpf
- NuExt.Minimal.Mvvm.AvalonDock
- NuExt.System
- NuExt.System.Data
- NuExt.System.Data.SQLite
Issues and PRs are welcome. Keep changes minimal and performance-conscious.
MIT. See LICENSE.