Skip to content

Latest commit

 

History

History
152 lines (117 loc) · 5.33 KB

File metadata and controls

152 lines (117 loc) · 5.33 KB

VMx C# examples

Three self-contained demos of the VMx C# package. Generated architecture diagrams for all examples live in ../DIAGRAMS.md.

1. Setup

Each project carries its own .csproj and currently resolves VMx from the local source build. After the first NuGet publication, a copied template may replace that project reference with the VMx package name.

dotnet restore

2. Example 1 — console/HelloVMx/ (console)

Minimal console demo. Demonstrates:

  1. Building a ComponentVM<UserModel> with the fluent builder.
  2. Subscribing to hub messages (ConstructionStatusChangedMessage and PropertyChangedMessage).
  3. The full lifecycle: construct → model mutations → destruct → dispose.
  4. The equality guard: setting the same model value emits no hub message.

Run:

Diagram: csharp-console-hello-vmx.svg (HTML, PNG).

cd console/HelloVMx
dotnet run

Cross-platform — runs anywhere the .NET SDK runs. The project targets net8.0, so a host that only has a newer runtime installed (e.g. .NET 9, no .NET 8) fails at launch with You must install or update .NET … 8.0.0 … was not found. On such a host, roll forward to the installed major:

DOTNET_ROLL_FORWARD=Major dotnet run

(The avalonia/NotesShowcase flagship also targets net8.0 and needs the same roll-forward when only a newer runtime is present.)


3. Example 2 — wpf/TodoApp/ (WPF + MVVM)

Platform: Windows only. WPF is a Windows-only UI framework, so this example only launches on Windows. dotnet restore and dotnet build succeed cross-platform (the off-Windows TargetFramework drops the -windows suffix), but dotnet run requires Windows.

A todo app that wires VMx into a WPF view. Demonstrates:

  • TodoItemVM composing a ComponentVM<TodoItem> (rather than subclassing it) and exposing Title/Done/ToggleDoneCommand for the item template — illustrates the composition pattern when you need view-only properties that aren't part of the model.
  • MainWindowViewModel holding an ObservableCollection<TodoItemVM> bound to the ListBox plus a VMx RelayCommand (AddCommand) whose task calls the internal AddItem(string); the Add button binds Command="{Binding AddCommand}". (The Python tk/todo_app example uses a CompositeVM<TodoItemVM> for its collection — both flavors drive the add through a VMx RelayCommand, each idiomatic for its UI toolkit.)
  • MainWindow.xaml — pure view; XAML data binding against TodoItemVM's INotifyPropertyChanged surface (the outer wrapper forwards the inner ComponentVM<TodoItem>'s hub-published PropertyChangedMessage("Model") to standard INPC for Title / Done) plus the ICommand-exposing ToggleDoneCommand.

Run (Windows only):

Diagram: csharp-wpf-todo-app.svg (HTML, PNG).

cd wpf/TodoApp
dotnet run

dotnet restore and dotnet build succeed cross-platform; the app only launches on Windows because of the WPF target.


4. Example 3 — avalonia/NotesShowcase/ (Avalonia + MVVM, flagship)

The Notes Workspace flagship app — a cross-platform XAML editor on Avalonia 12 + .NET 8 that exercises 19 distinct VMx features in one cohesive scenario (notebooks tree, paged + filterable notes list, FormVM editor, capability-aware action bar, notifications, async lifecycle, dialogs, token-paged global search, edit/preview state, tag autocomplete, AggregateVM6 root, and the v2.4.0 ThemeVM scenario contract). Pure-VM contract enforced; every *.axaml.cs code-behind is limited to the view constructor's AvaloniaXamlLoader.Load(this) call.

Run (macOS / Linux / Windows):

Diagram: csharp-avalonia-notes-showcase.svg (HTML, PNG).

cd ../../    # repo root
dotnet run --project examples/csharp/avalonia/NotesShowcase

See avalonia/NotesShowcase/README.md for the project layout, feature-traceability table, and keyboard shortcuts. Cross-flavor parity is documented in ../notes-showcase-parity.md; the canonical scenario contract lives at ../../spec/proposals/2026-05-29-notes-showcase-scenario.md.


5. IDE workflow

Open Examples.sln in Visual Studio or Rider to step through the C# example projects with the debugger attached.

6. Project layout

examples/csharp/
├── Examples.sln
├── README.md              # this file
├── console/
│   └── HelloVMx/
│       └── HelloVMx.csproj
├── wpf/
│   └── TodoApp/
│       └── WpfTodoApp.csproj
└── avalonia/
    ├── NotesShowcase/
    │   └── NotesShowcase.csproj
    └── NotesShowcase.Tests/
        └── NotesShowcase.Tests.csproj