fix/inactive-toolbar-buttons #38
1 changed files with 19 additions and 0 deletions
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.
commit
aa098daed5
|
|
@ -64,6 +64,25 @@ Quelques règles non capturées par `.editorconfig` :
|
||||||
- Préférer les types BCL (`int`, `string`) aux types framework
|
- Préférer les types BCL (`int`, `string`) aux types framework
|
||||||
(`Int32`, `String`).
|
(`Int32`, `String`).
|
||||||
- Préférer les expressions de pattern matching aux casts explicites.
|
- 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<TView>()`). 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
|
## Branches & commits
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue