🕓 7 MIN We are proud to …
When developing applications, effective navigation is crucial for creating intuitive and efficient user experiences. This guide focuses specifically on Uno Platform’s Uno.Extensions Navigation feature, a powerful routing framework that extends beyond the capabilities of native frame navigation in Uno Platform.
Uno.Extensions Navigation provides a comprehensive system designed to handle a wide range of navigation scenarios in modern app development. It’s important to note that this navigation framework is distinct from the basic frame navigation native to Uno Platform, offering more advanced features and flexibility.
Uno Platform’s navigation system is designed to handle:
Navigation in Uno Platform can be triggered for various reasons:
The platform’s architecture ensures that navigation is accessible from anywhere in your app:
Moreover, Uno Platform’s navigation system is designed to make efficient use of available data, supporting:
In this guide, we’ll explore eight key aspects of navigation using the Uno.Extensions Navigation, each with its own dedicated tutorial:
Each section will provide an overview of the concept, code examples, and a link to a detailed step-by-step tutorial. Whether you’re new to Uno Platform or looking to master its navigation capabilities, this article will equip you with the knowledge to implement efficient and user-friendly navigation in your apps.
Let’s dive in and explore the power and flexibility of navigation in Uno Platform.
At its core, navigation in Uno Platform revolves around moving between different pages or views. The platform provides multiple ways to achieve this:Â
// Code-behind navigation example
_ = this.Navigator()?.NavigateViewAsync(this);
// ViewModel-based navigation example
await _navigator.NavigateViewModelAsync(this);
When you need more control over navigation logic, you can implement navigation directly in your code:
public class MainViewModel
{
private readonly INavigator _navigator;
public MainViewModel(INavigator navigator)
{
_navigator = navigator;
}
public async Task NavigateToSecondPage()
{
await _navigator.NavigateViewModelAsync(this);
}
}
Uno Platform allows for declarative navigation directly in your XAML:
For more complex navigation scenarios, Uno Platform allows you to define custom routes:
views.Register(
new ViewMap(),
new DataViewMap()
);
routes.Register(
new RouteMap("", View: views.FindByViewModel(),
Nested: [
new ("Main", View: views.FindByViewModel()),
new ("Second", View: views.FindByViewModel()),
]
)
);
Uno Platform’s navigation system extends to displaying dialogs:
var result = await _navigator.ShowMessageDialogAsync(
this,
title: "Confirm Action",
content: "Are you sure?",
buttons: [
new DialogAction("Yes"),
new DialogAction("No")
]
);
For scenarios where you need to navigate to select a value:
GetDataAsync<T>()
to navigate and retrieve selected dataResultDataViewMap<TView, TViewModel, TData>
for type-safe navigation with return valuesNavigation.Request="-"
for navigating back with selected data
// Define the data type
public record Widget(string Name, double Weight);
// In SecondViewModel
public Widget[] Widgets { get; } =
[
new Widget("NormalSpinner", 5.0),
new Widget("HeavySpinner", 50.0)
];
// In MainViewModel
public async Task GoToSecondPage()
{
var widget = await _navigator.GetDataAsync(this);
// Use the selected widget
}
In XAML, you can set up a ListView for selection:
For more efficient navigation, you can use ResultDataViewMap
:
// In route registration
new ResultDataViewMap()
// Updated navigation in MainViewModel
public async Task GoToSecondPage()
{
var widget = await _navigator.GetDataAsync(this);
}
This approach allows Navigation to resolve the correct view based on the requested data type.
Uno Platform supports both modal and flyout dialogs:
// Displaying a dialog
_ = this.Navigator()?.NavigateViewAsync(this, qualifier: Qualifiers.Dialog);
// In XAML
For data-driven navigation scenarios like master-detail views:
// Navigating with data
var widget = new Widget("ExampleWidget", 10.0);
await _navigator.NavigateDataAsync(this, data: widget);
// Receiving data in the destination ViewModel
public class SecondViewModel
{
public SecondViewModel(Widget widget)
{
// Use the widget data
}
}
The trick here? Focus on understanding how your app’s structure and user flow work together. Start small with basic navigation and, as you get more comfortable, feel free to add those more advanced techniques to easily create everything from simple page transitions to more intricate, data-driven flows.
And hey, if you ever need more help or a step-by-step breakdown, don’t hesitate to dive into the official Uno Platform docs linked in this article or join the community on Discord.
Happy Coding!
Tags: XAML, WPF, Xamarin, UWP, Silverlight, .NET, Windows, C#, XAML
🕓 10 MIN Each release, we don’t …
🕓 9 MIN Ever wondered how to …
Uno Platform
360 rue Saint-Jacques, suite G101,
Montréal, Québec, Canada
H2Y 1P5
USA/CANADA toll free: +1-877-237-0471
International: +1-514-312-6958
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
Uno Platform 5.2 LIVE Webinar – Today at 3 PM EST – Watch