RouteNav.Avalonia includes controls and commands that turn UI interactions into route navigation.
RouteButton derives from Avalonia Button and implements IRouteItem.
<routing:RouteButton RoutePath="/main/details" Content="Open details" />
<routing:RouteButton RoutePath="details" Content="Open details on current stack" />Properties:
RouteUri- the route URI to navigate to.RoutePath- convenience setter for relative or absolute route paths.Target- theNavigationTargetused for navigation.
Example with target:
<routing:RouteButton RoutePath="/main/details"
Target="Dialog"
Content="Open details dialog" />RouteMenuItem is the menu equivalent of RouteButton.
<routing:RouteMenuItem Header="Settings" RoutePath="/main/settings" />Use it in normal Avalonia menus when you want route navigation instead of custom click handlers.
RouteCommand implements ICommand and can be used from view models or command bindings.
public ICommand OpenSettings { get; } = new RouteCommand
{
RoutePath = "/main/settings",
Target = NavigationTarget.Self
};You can also create a command from any IRouteItem:
var command = new RouteCommand(routeButton);HyperlinkButton and HyperlinkLabel behave like hyperlinks. They inspect the target URI:
- Internal RouteNav URI ->
Navigation.PushAsync(...). - External URI/file -> Avalonia's platform launcher.
<controls:HyperlinkButton NavigateUri="https://avaloniaui.net/"
Content="Avalonia" />
<controls:HyperlinkButton RoutePath="/main/details"
Content="Internal details link" />
<controls:HyperlinkLabel NavigateUri="https://avaloniaui.net/">
Avalonia website
</controls:HyperlinkLabel>
<controls:HyperlinkLabel RoutePath="/main/details">
Internal details link
</controls:HyperlinkLabel>Both expose:
NavigateUri/RouteUri- target URI.RoutePath- route-path convenience setter.Target- RouteNav navigation target.IsVisited- visited state.TrackIsVisited- sets visited state after successful launch/navigation.
SidebarMenu is the control used by SidebarMenuPageStack. It composes Avalonia 12's native DrawerPage internally.
Typical apps do not create SidebarMenu directly; they create a SidebarMenuPageStack and add menu items:
var sidebarStack = new SidebarMenuPageStack("sidebar", "Sidebar");
Navigation.UIPlatform.AddStack(sidebarStack);
sidebarStack.AddMenuItem<HomePage>(String.Empty, "Home");
sidebarStack.AddMenuItem<ReportsPage>("reports", "Reports");
sidebarStack.AddMenuItem("/tabbed/summary", "Tabbed: Summary");Public members:
MenuItems/MenuItemsSource- menu items shown in the drawer.SelectedMenuItem- selected item.SelectedMenuItemChanged- raised when selection changes.Page- content page hosted in the drawer content area.DisplayMode- drawer behavior.InlineThresholdWidth- breakpoint forAutomode.SidebarHeader/SidebarFooter- drawer header/footer content.
Display modes:
sidebarStack.DisplayMode = SidebarMenu.DisplayModeEnum.Auto;Auto maps to Avalonia DrawerBehavior.Auto and switches between split/overlay behavior based on the threshold. Inline, Overlay and CompactOverlay map to the corresponding native drawer layouts.
SidebarMenuItem carries the menu text and route.
var item = new SidebarMenuItem
{
Text = "Settings",
RoutePath = "/main/settings",
Target = NavigationTarget.Parent
};For most apps, prefer SidebarMenuPageStack.AddMenuItem(...) because it adds the menu item and optionally registers the page in one call.
RouteNav also ships simple command helpers:
var command = new Command(() => Save());
var typedCommand = new Command<string>(value => Search(value));Use these when you need a lightweight ICommand implementation independent of route navigation.