Primary WPF APIs:
NavigationWindowFrame and PagePrimary Avalonia patterns:
ContentControl or TransitioningContentControl with view-model-based routingTabControl/SplitView shells for multi-surface navigation| WPF | Avalonia |
|---|---|
Frame.Navigate(page) |
update current route/view-model and swap content |
Page classes |
UserControl views + view-model route models |
| journal/history | explicit navigation stack service |
Avalonia core does not include a direct Frame/Page replacement control.
WPF XAML:
<Frame x:Name="MainFrame" NavigationUIVisibility="Hidden" />
Avalonia XAML:
<TransitioningContentControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MyApp.ViewModels"
x:DataType="vm:ShellViewModel"
Content="{CompiledBinding CurrentViewModel}" />
using System.Collections.Generic;
public interface INavigationService
{
void Navigate(object routeViewModel);
bool CanGoBack { get; }
void GoBack();
}
public sealed class NavigationService : INavigationService
{
private readonly Stack<object> _history = new();
private object? _current;
public bool CanGoBack => _history.Count > 0;
public void Navigate(object routeViewModel)
{
if (_current is not null)
_history.Push(_current);
_current = routeViewModel;
}
public void GoBack()
{
if (_history.Count > 0)
_current = _history.Pop();
}
}
main, sidebar, dialog) with independent state.