Sanet.MVVM.Core
1.7.3
dotnet add package Sanet.MVVM.Core --version 1.7.3
NuGet\Install-Package Sanet.MVVM.Core -Version 1.7.3
<PackageReference Include="Sanet.MVVM.Core" Version="1.7.3" />
<PackageVersion Include="Sanet.MVVM.Core" Version="1.7.3" />
<PackageReference Include="Sanet.MVVM.Core" />
paket add Sanet.MVVM.Core --version 1.7.3
#r "nuget: Sanet.MVVM.Core, 1.7.3"
#:package Sanet.MVVM.Core@1.7.3
#addin nuget:?package=Sanet.MVVM.Core&version=1.7.3
#tool nuget:?package=Sanet.MVVM.Core&version=1.7.3
Sanet.MVVM.Core
MVVM base classes and contracts for .NET 10.
Installation
dotnet add package Sanet.MVVM.Core
Minimal usage
using Sanet.MVVM.Core.ViewModels;
public sealed class MainViewModel : BaseViewModel
{
private string _title = "Hello";
public string Title
{
get => _title;
set => SetProperty(ref _title, value);
}
public override void AttachHandlers()
{
// Subscribe to services or events.
}
public override void DetachHandlers()
{
// Unsubscribe here.
}
}
BindableBase
BindableBase is an abstract base class that implements INotifyPropertyChanged. It exposes the
following members to derived classes:
NotifyPropertyChanged([CallerMemberName] string? propertyName = null)raisesPropertyChanged. It isprotected virtual.SetProperty<T>(ref T backingStore, T value, [CallerMemberName] string? propertyName = null)compares the current and new value withEquals, assigns the field, and raisesPropertyChangedonly when the value changes.NotifyAllPropertiesChanged()raisesPropertyChangedwith an empty property name so that all bindings refresh.
BaseViewModel
BaseViewModel is abstract and derives from BindableBase.
IsBusyis a bindable busy flag.BackCommandis anICommandthat callsINavigationService.NavigateBackAsync.NavigationServicereturns the navigation service supplied to the constructor or toSetNavigationService. Accessing it before initialization throwsArgumentNullException.- Two protected constructors are available: a parameterless one and
BaseViewModel(INavigationService navigationService). SetNavigationService(INavigationService navigationService)initializes or replaces the navigation service after construction.AttachHandlers()andDetachHandlers()are virtual hooks for subscribing and unsubscribing from services or events. The Avalonia base view calls them when the view enters or leaves the visual tree.
BaseViewModel does not implement IDisposable or IAsyncDisposable. Derived view models may add
either interface when they need to release resources.
Contracts
IBaseViewexposes anobject? ViewModel { get; set; }property.IBaseView<out TViewModel>is the typed variant used byBaseView<TViewModel>.INavigationServicedefines navigation, back navigation, result-returning overlays, view registration, andAskForActionAsync.IResultProvider<TResult>definesTask<TResult> GetResultAsync()for view models that return a result.UiActionis a record withTitle, an optionalCommand, and an optionalCommandParameter.IExternalNavigationServicedefinesOpenUrlAsync(string url)andOpenEmailAsync(string emailAddress, string subject).
Notes and limitations
Sanet.MVVM.Coredoes not create a dependency-injection container and does not provide a navigation implementation. UseSanet.MVVM.Navigation.Avaloniafor Avalonia, or implementINavigationServiceyourself.- Always initialize
NavigationServicebefore a view model uses navigation.
Links
License
MIT. See LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- AsyncAwaitBestPractices.MVVM (>= 11.0.0)
NuGet packages (10)
Showing the top 5 NuGet packages that depend on Sanet.MVVM.Core:
| Package | Downloads |
|---|---|
|
Sanet.MakaMek.Presentation
An Attempt of Classic BattleTech game implementation. Presentation Logic |
|
|
Sanet.MakaMek.Avalonia.Controls
Avalonia UI controls for MakaMek |
|
|
Sanet.MekForge.Core
An Attempt of Classic BattleTech game implementation. Game Logic |
|
|
Sanet.MVVM.Navigation.Avalonia
Sanet MVVM Navigation implementation for Avalonia. Works with AvaloniaUI v12 |
|
|
Sanet.MVVM.Views.Avalonia
Avalonia BaseView for Sanet MVVM. Works with AvaloniaUI v12 |
GitHub repositories
This package is not used by any popular GitHub repositories.