MVVM view models and controls for WPF and .NET MAUI that reduce boilerplate and simplify data binding. Write the view models once, on plain .NET, and put either UI on top.
Written by Benjamin Day
Pluralsight Author | Microsoft MVP
https://www.benday.com
https://www.honestcheetah.com
info@benday.com
YouTube: https://www.youtube.com/@_benday
π New book: Azure Cosmos DB for .NET Developers: From Document Thinking to Production Patterns β It's the book on Cosmos DB for .NET developers! Document modeling with aggregate roots, hierarchical partition keys, request unit economics, Change Feed patterns, and a complete production case study β all in C# and ASP.NET Core.
Benday.Presentation.Core (net10.0, net11.0)
βββ Benday.Presentation.Wpf (net10.0-windows, net11.0-windows)
βββ Benday.Presentation (.NET MAUI 10 and 11)
βββ Benday.Presentation.Controls
Up to version 2.1 the view models lived in Benday.Presentation, which required MAUI. In 3.0 they
moved to Benday.Presentation.Core. The namespace is still Benday.Presentation and the MAUI
package forwards the moved types, so existing MAUI code keeps working.
- ViewModelField - One object per form field:
Value,IsVisible,IsEnabled,IsValidandValidationMessage - SelectableCollectionViewModel - Observable collections with automatic selection tracking (single or multi-select), drag-and-drop reordering via
Move(), and selection interception viaBeforeSetSelectedItem - FilterableListViewModel - A selectable collection with a
Filtertext property - MessagingViewModelBase / IMessageManager - Display message boxes and dialogs from your ViewModels
- ExceptionHandlingRelayCommand / ExceptionHandlingAsyncRelayCommand - Commands that catch and display exceptions automatically
- TextboxField - Text input with label and validation
- TextEditorField - Multi-line text input
- ComboboxField - Dropdown selection bound to SelectableCollectionViewModel
- ListboxField - List selection bound to SelectableCollectionViewModel
- LabelField - Display-only field with consistent styling
Both UI packages also have value converters (including VisibleIfNullValueConverter and
VisibleIfNotNullValueConverter) and an IMessageManager that shows a native message box.
Got ideas for features you'd like to see? Found a bug? Let us know by submitting an issue https://github.com/benday-inc/mvvm-presentation/issues. Want to contribute? Submit a pull request.
# WPF
dotnet add package Benday.Presentation.Wpf
# .NET MAUI
dotnet add package Benday.Presentation
dotnet add package Benday.Presentation.Controls
# a view model or test project with no UI
dotnet add package Benday.Presentation.Coreusing Benday.Presentation;
public class PersonViewModel : MessagingViewModelBase
{
public PersonViewModel(IMessageManager messages) : base(messages)
{
SaveCommand = new ExceptionHandlingAsyncRelayCommand(Messages, SaveAsync);
}
public ViewModelField<string> FirstName { get; } = new(string.Empty);
public ViewModelField<string> LastName { get; } = new(string.Empty);
public SingleSelectListViewModel Country { get; } = new(new[]
{
new SelectableItem(true, "Canada"),
new SelectableItem(false, "United States")
});
public ExceptionHandlingAsyncRelayCommand SaveCommand { get; }
private async Task SaveAsync()
{
FirstName.IsValid = !string.IsNullOrEmpty(FirstName.Value);
FirstName.ValidationMessage = FirstName.IsValid ? "" : "First name is required";
if (FirstName.IsValid)
{
await Task.Delay(500); // save somewhere; an exception here is shown to the user
}
}
}<Window xmlns:controls="clr-namespace:Benday.Presentation.Wpf.Controls;assembly=Benday.Presentation.Wpf">
<StackPanel>
<controls:TextboxField LabelText="First Name" DataContext="{Binding FirstName}" />
<controls:TextboxField LabelText="Last Name" DataContext="{Binding LastName}" />
<controls:ComboboxField LabelText="Country" DataContext="{Binding Country}" />
<Button Content="Save" Command="{Binding SaveCommand}" />
</StackPanel>
</Window>Set the window's DataContext to new PersonViewModel(new Benday.Presentation.Wpf.MessageBoxMessageManager()).
The controls need no styles or converters in App.xaml.
<ContentPage xmlns:controls="clr-namespace:Benday.Presentation.Controls;assembly=Benday.Presentation.Controls">
<VerticalStackLayout>
<controls:TextboxField LabelText="First Name" BindingContext="{Binding FirstName}" />
<controls:TextboxField LabelText="Last Name" BindingContext="{Binding LastName}" />
<controls:ComboboxField LabelText="Country" BindingContext="{Binding Country}" />
<Button Text="Save" Command="{Binding SaveCommand}" />
</VerticalStackLayout>
</ContentPage>Set the page's BindingContext to new PersonViewModel(new Benday.Presentation.MessageBoxMessageManager()).
In MAUI, App.xaml has to merge Styles/Styles.xaml from Benday.Presentation and declare
NotVisibilityValueConverterInstance; see Benday.Presentation.DemoApp/App.xaml.
The controls automatically handle labels, validation messages, visibility, and enabled state.
Full documentation: https://benday-inc.github.io/mvvm-presentation/
Two demo apps show every control over the same MainPageViewModel (in Benday.Presentation.DemoApp.Api, a plain .NET project):
- Benday.Presentation.Wpf.DemoApp - WPF.
dotnet run --project Benday.Presentation.Wpf.DemoApp - Benday.Presentation.DemoApp - .NET MAUI 11, across platforms:
| iOS | macOS | Windows |
|---|---|---|
![]() |
![]() |
![]() |
| Class | Purpose |
|---|---|
ViewModelBase |
Base class with INotifyPropertyChanged implementation and DebuggingTag |
ViewModelField<T> |
Wraps a field value with Value, IsVisible, IsEnabled, IsValid, ValidationMessage |
SelectableCollectionViewModel<T> |
Collection with selection tracking, OnItemSelected event, Move() for reordering, BeforeSetSelectedItem for interception |
SingleSelectListViewModel |
Specialized collection for dropdown/combobox scenarios |
MessagingViewModelBase |
Extends ViewModelBase with IMessageManager for dialogs |
FilterableListViewModel<T> |
A selectable collection filtered by its Filter text |
ExceptionHandlingRelayCommand |
Command that catches and displays exceptions; optional canExecute |
ExceptionHandlingAsyncRelayCommand |
The async version: awaits the action, cannot be re-run while it is running |
dotnet build Benday.Presentation-Wpf.sln # Core, WPF, WPF demo, all tests (no MAUI workload needed)
dotnet build Benday.Presentation-Maui.sln # Core, MAUI packages, MAUI demo (needs the MAUI workload)
dotnet test --solution Benday.Presentation-Wpf.slnPull requests and pushes to master are built and tested by GitHub Actions
(.github/workflows/benday-presentation.yml); a push to master also publishes
any package version that is not on nuget.org yet.
MIT License - see LICENSE for details.


