From aa098daed5723f932dcb8a8a191ca1b484c38ef7 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Wed, 19 Aug 2026 15:20:29 +0100 Subject: [PATCH] doc: codify PostIt navigation rule via ViewLocator Navigation in PostIt is owned by src/PostIt/PostIt/ViewLocator.cs. To open a screen, the caller assigns the target ViewModel to the host's CurrentViewModel (which binds the IContentControl.Content); the ViewLocator decides which Control instance to push and resolves it through DI. ViewModels never instantiate views nor resolve them from DI directly. Add the rule and a canonical example to CONTRIBUTING.md so contributors do not re-derive the pattern from scratch each time. --- CONTRIBUTING.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4730e18c..a2c9aeb1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -64,6 +64,25 @@ Quelques règles non capturées par `.editorconfig` : - Préférer les types BCL (`int`, `string`) aux types framework (`Int32`, `String`). - Préférer les expressions de pattern matching aux casts explicites. +- **Navigation (PostIt)** : la navigation est contrôlée par + `src/PostIt/PostIt/ViewLocator.cs`. Pour ouvrir un écran, + on affecte le ViewModel cible à la propriété `CurrentViewModel` + du `MainPageViewModel` (qui binde l'`IContentControl.Content` + de la page hôte). Tant que la vue correspondante est supportée + par le `ViewLocator`, ce dernier décide de l'instance de + `Control` à pousser en navigation, et il l'obtient de la DI + (`_services.GetRequiredService()`). On n'instancie + jamais une `View` à la main depuis un ViewModel, on ne + récupère jamais une `View` depuis la DI directement dans un + ViewModel. Exemple canonique : + + ```csharp + [RelayCommand] + internal void OpenSettings() + { + CurrentViewModel = SettingsModel; + } + ``` ## Branches & commits