public abstract class NavigationRegion : INotifyPropertyChanged One navigation region, independent of its content type, for hosts that present a region without knowing it. NavigationRegion is the typed region, and every region is one.
Remarks
NavigationRegion.CurrentEntry and NavigationRegion.History return the region's typed entries. The entry in a Committed returned by NavigationRegion.BackAsync, NavigationRegion.BackToAsync, NavigationRegion.ClearHistoryAsync, NavigationRegion.ClearAsync or NavigationRegion.ReplaceBorrowedAsync is a NavigationEntry of Object, a different instance from the typed entry. Compare entries by NavigationEntry.Id, not by reference.
Only RunicNavigator.CreateRegion creates regions, so the class can't be derived from outside Runic.Navigation, and members can be added to it in a minor release.
Properties
Admission
public NavigationAdmission Admission { get; } Gets how the region admits a request while an earlier one runs (NavigationRegionOptions.Admission).
CanGoBack
public bool CanGoBack { get; } Gets whether a retained entry exists to go back to.
Current
public object? Current { get; } Gets the current content, or null when the region is empty.
CurrentEntry
public NavigationEntry? CurrentEntry { get; } Gets the current entry, or null when the region is empty.
History
public IReadOnlyList<NavigationEntry> History { get; } Gets the retained entries below the current entry, from bottom to top.
IsBusy
public bool IsBusy { get; } Gets whether a request of this region has not completed: from its admission until its task completes, so it spans the guards, the preparation, the commit and the retirement of the departed entries. A request made after an awaited request of the region resumed never finds the region busy because of that request.
Remarks
A Back whose callers have all cancelled stops counting when the last of them gets NavigationRejection.Cancelled, even while its departure guard is still running because it hasn't observed the token yet. That Back never commits. A request admitted meanwhile waits for its guard to end before its own guards run, as it waits for any earlier request of the region.
NavigationRegion.PropertyChanged reports a change in a model turn, like NavigationRegion.IsTransitioning; the change of a request that completes is posted, so the notification can trail its task. The property's value is authoritative.
IsTransitioning
public bool IsTransitioning { get; } Gets whether a transition of this region is in flight: from a request's admission until its commit decision. It is false again in the commit turn, before the request's task completes.
Methods
AddDepartureGuard
public IDisposable AddDepartureGuard(INavigationRegionGuard guard, NavigationRegionGuardOptions? options = null) Registers a guard that is asked before a transition departs from this region: a request to the region, or to a region whose plan resets or closes it or leaves it, as a tab switch leaves the tab's page regions, or a change of the NavigationSelection the region is in that leaves or removes it. It is asked once per transition, after the departure guards of the entries (INavigationDepartureGuard), or before them with NavigationRegionGuardOptions.Order, and only when an entry of the region departs: a push into an empty region asks it not.
Parameters
guardThe guard.
optionsWhen the guard is asked; by default after the entries' guards, and skipped for retained entries and for ClearHistory.
Returns
An IDisposable that removes the guard.
Remarks
The region guards of a transition run region by region, deepest first, each region's guards in registration order, then the navigator's (RunicNavigator.AddDepartureGuard): first those asked NavigationRegionGuardOrder.BeforeEntries, then the entries' guards, then those asked NavigationRegionGuardOrder.AfterEntries. A guard is skipped when the transition only retains the region's entries, unless NavigationRegionGuardOptions.AskOnRetain, and for a NavigationOperation.ClearHistory request, unless NavigationRegionGuardOptions.AskOnClearHistory.
false rejects the transition as NavigationRejection.Guard with no Rejected.By entry; a guard that throws fails it in NavigationPhase.Guarding (event 1060, with the guard's type as EntryType). The guards are read when the transition starts guarding: a guard removed before its turn is not asked, and one added later waits for the next transition. Navigator disposal asks no guards.
BackAsync
public ValueTask<NavigationResult<object>> BackAsync(NavigationRequestOptions? options = null, CancellationToken cancellationToken = default) Retires the current entry and resumes the top retained entry.
Remarks
Compare the result's entry with this region's entries by NavigationEntry.Id.
BackToAsync
public ValueTask<NavigationResult<object>> BackToAsync(NavigationEntryId entry, NavigationRequestOptions? options = null, CancellationToken cancellationToken = default) Retires every entry above entry and resumes it.
Remarks
Compare the result's entry with this region's entries by NavigationEntry.Id.
ClearAsync
public ValueTask<NavigationResult<object>> ClearAsync(NavigationRequestOptions? options = null, CancellationToken cancellationToken = default) Retires every entry. The region becomes empty.
Remarks
Compare the result's entry with this region's entries by NavigationEntry.Id.
ClearHistoryAsync
public ValueTask<NavigationResult<object>> ClearHistoryAsync(NavigationRequestOptions? options = null, CancellationToken cancellationToken = default) Retires every retained entry. The current entry stays.
Remarks
Compare the result's entry with this region's entries by NavigationEntry.Id.
ConfirmDepartureAsync
public ValueTask<NavigationResult<object>> ConfirmDepartureAsync(NavigationDepartureKind kind, Action? onConfirmed = null, NavigationRequestOptions? options = null, CancellationToken cancellationToken = default) Asks the departure guards of the current entry, and of the entries below it, whether it may depart as kind, without navigating: a transition of this region whose commit changes no stack and no entry's state, and runs the guards' NavigationDeparture.OnCommitted actions and then onConfirmed in its commit turn. For work outside navigation that would end what the entry shows, such as switching the account while a page with unsaved tabs sits in history.
Parameters
kindHow the current entry would depart: retired, so its work is lost, or retained.
onConfirmedRuns in the commit turn when every guard agreed, after their actions; or
null.optionsThe request's expected current entry, admission and requester.
cancellationTokenCancels the request before its commit.
Exceptions
ArgumentOutOfRangeExceptionkindis not a defined value.
Remarks
It asks what that departure would ask, with NavigationOperation.Confirm: for NavigationDepartureKind.Retire, every entry of the regions the current entry's owned content owns, deepest first, as NavigationDepartureKind.Retire, and the current entries of the regions borrowed content owns as NavigationDepartureKind.Retain; for NavigationDepartureKind.Retain, the current entry of each region below it, as a tab switch does. Of a selection's regions, a retained departure follows only the selected one. The current entry is asked last, then the region and navigator guards by their options.
It is admitted like a request of the region (its NavigationRegion.Admission, or NavigationRequestOptions.Admission): by default it supersedes the region's pending requests, with NavigationAdmission.Queue it waits for them. A commit in an asked region while the guards run supersedes it. Its result is Committed with the current entry when every guard agreed and onConfirmed ran; otherwise a rejection (NavigationRejection.Guard with the vetoing entry, NavigationRejection.Cancelled, NavigationRejection.Busy, ...), Superseded or Failed. An empty region asks nothing and commits. The answer holds for the commit turn: do the agreed work in onConfirmed, which must not pump or await navigation. When it throws, the result is Failed in NavigationPhase.Committing (event 1062), after the guards' actions ran.
GetPath
public NavigationRegionPath GetPath(INavigationRouteMap? routes = null) Gets the region's entries, and the regions and selections below them, as a serializable path, like RunicNavigator.GetPath does for the whole navigator.
Parameters
routesThe route map, or
nullfor theINavigationRouteMapof the navigator's services.
Exceptions
InvalidOperationExceptionNo route map was passed or registered.
OpenRouteAsync
public ValueTask<NavigationResult<object>?> OpenRouteAsync(string route, NavigationRouteOpen mode = NavigationRouteOpen.Push, INavigationRouteMap? routes = null, NavigationRequestOptions? options = null, CancellationToken cancellationToken = default) Opens a route path, such as one from a deep link (NavigationRouteLinks.TryGetRoute), a notification or an address bar, in this region: the route map creates the target, and mode decides the request.
Parameters
routeThe route path, with or without a leading
/.modeHow to open it;
NavigationRouteOpen.Pushby default.routesThe route map, or
nullfor theINavigationRouteMapof the navigator's services.optionsThe options of the requests.
cancellationTokenCancels the requests before they commit.
Returns
The result of the last request, or null when no route matches.
Exceptions
InvalidOperationExceptionNo route map was passed or registered.
Remarks
The route is untrusted input: only the map's routes open, with typed parameters, and an unmatched route returns null (log event 1221) without navigating. The requests are ordinary ones, guarded and returned as a NavigationResult; when the route is already where mode would put it, the result is Committed with the current entry and nothing changes.
ReplaceBorrowedAsync
public ValueTask<NavigationResult<object>> ReplaceBorrowedAsync(object content, NavigationRequestOptions? options = null, CancellationToken cancellationToken = default) Replaces the current entry with borrowed content. For presentation adapters that select existing models without knowing the region's content type, such as Runic.Navigation.Wpf's NavigationSelector; application code calls NavigationRegion.ReplaceAsync.
Exceptions
ArgumentExceptionThe content is not assignable to
NavigationRegion.ContentType.
Remarks
The engine runs the same guards and lifetime rules as typed Replace. The caller retains ownership.
RestoreAsync
public ValueTask<NavigationRestoreResult> RestoreAsync(NavigationRegionPath path, NavigationRestoreOptions? options = null, CancellationToken cancellationToken = default) Rebuilds path in this region with guarded navigation requests, as RunicNavigator.RestoreAsync does for each region; what can't be restored is reported, not thrown.
Parameters
pathThe region's path, such as one
NavigationRegion.GetPathreturned.optionsThe route map, what an unmapped entry does, and the bounds; the defaults without it.
cancellationTokenCancels the requests not yet committed; the restore then stops.
Exceptions
InvalidOperationExceptionNo route map was passed or registered.
OperationCanceledExceptioncancellationTokenwas cancelled.
WhenIdleAsync
public ValueTask WhenIdleAsync(CancellationToken cancellationToken = default) Completes when NavigationRegion.IsBusy is false: when no request of this region is running. Unlike RunicNavigator.WhenIdleAsync, it doesn't wait for other regions or for retirements that no request of this region awaits, nor for the guard of a Back whose callers have all cancelled.
Parameters
cancellationTokenStops waiting.
Remarks
A hook of a transition of this region that awaits it deadlocks: the region is busy while the hook runs.
Events
PropertyChanged
public event PropertyChangedEventHandler? PropertyChanged Raised inside a model turn after a commit, for NavigationRegion.Current, NavigationRegion.CurrentEntry, NavigationRegion.History, NavigationRegion.CanGoBack, NavigationRegion.IsTransitioning and NavigationRegion.IsBusy. Each handler is called separately; one that throws is logged and does not skip the others.