Repository navigation
Replies: 3 comments 13 replies
|
I don't really agree. Avalonia is a UI framework so they handle the View side. You can build around it. The wiring is tricky, but there are a few approaches depending whether you want navigation to be a side effect or whether you need synchronization. You can start by writing a ViewModel-First abstraction around Messaging is another option that we use to decouple and events being another option. This is not too hard if your app is single window, but multiple windows is substantially harder. I use an approach with DI scoping for our multiple window app and while the VM side is completely MVVM pure in this area, I wouldn't recommend it. It's very complex wiring and you need to churn IoC containers or otherwise never use transient |
|
The name |
|
I’m currently integrating NavigationPage into my navigation framework based on my own preferences (a navigation framework inspired by MSDI and Prism-style design). I’ve found that NavigationPage is a very lightweight and fundamental design—you can think of it as a ContentControl with more features.It is not tightly coupled with INavigation. |
Uh oh!
There was an error while loading. Please reload this page.
Avalonia 12.0 ships
NavigationPageandINavigationunderAvalonia.Controls, signaling this as the framework's canonical navigation solution. However, the API design is fundamentally at odds with Avalonia's own established MVVM conventions. Three specific contradictions:1. Contradicts the ViewLocator pattern promoted by Avalonia's own project templates
Avalonia's official project template introduces
ViewLocatoras the first thing new developers encounter. The entire point ofViewLocatoris VM-first: you navigate by ViewModel type, and the framework resolves the View automatically. The new navigation API inverts this entirely — the caller is responsible for instantiating the View directly:These two patterns cannot coherently coexist in the same application. A developer following the project template's conventions has no natural path to adopt this navigation API without abandoning the VM-first model they were taught.
2.
PopToPageAsync(Page page)forces cross-layer object retentionPopToPageAsyncrequires the caller to hold a reference to the targetPageinstance — a View-layer object. In any MVVM architecture, this means a ViewModel must either retain a reference to a View, or retrieve it by walking the navigation stack at call time:This is not a usage concern — it is an inevitable consequence of the interface contract. Any developer needing
PopTosemantics in an MVVM application will be pushed toward anti-patterns such as static Page registries or ViewModels holding View references. The interface provides no alternative.3.
Avalonia.Controlsnamespace implies canonical status this API does not warrantPlacing this API under
Avalonia.Controls— the same namespace asButton,ListBox, andTextBox— signals to every Avalonia developer that this is the intended, general-purpose navigation solution. In reality, this API is self-consistent only in code-behind / no-DI scenarios similar to Xamarin.Forms or MAUI. For the majority of Avalonia applications that use DI and MVVM, it is a trap.Suggested direction
A VM-first API would be consistent with Avalonia's existing conventions and close this contradiction:
The View resolution can be delegated to
ViewLocator(or a registeredIDataTemplate) internally, which is exactly the mechanism Avalonia already ships for this purpose.If the current API is intentionally scoped to mobile / code-behind scenarios, it should be namespaced accordingly (e.g.
Avalonia.Controls.Navigationor a dedicated package) and the documentation should make the scope explicit. Placing it underAvalonia.Controlswithout qualification sets a false expectation for the majority of the Avalonia user base.All reactions