NavigationRegion<TContent> class

Namespace Runic.Navigation in Runic.Navigation 0.23.0

public sealed class NavigationRegion<TContent> : NavigationRegion where TContent : class

Inherits or implements NavigationRegion.

One navigation region: a stack of typed entries whose top is NavigationRegion.Current. State changes commit in one model turn and raise NavigationRegion.PropertyChanged inside that turn.

Type parameters

TContent

The content type presented by the region.

Remarks

Operations throw only for argument errors and ownership violations; every navigation outcome is returned as a NavigationResult. Called from inside a model turn, an operation is admitted without blocking and continues on the thread pool; do not block on it there.

Properties

Current

public TContent? Current { get; }

Gets the current content, or null when the region is empty.

CurrentEntry

public NavigationEntry<TContent>? CurrentEntry { get; }

Gets the current entry, or null when the region is empty.

History

public IReadOnlyList<NavigationEntry<TContent>> History { get; }

Gets the retained entries below the current entry, from bottom to top.

Methods

BackAsync

public ValueTask<NavigationResult<TContent>> BackAsync(NavigationRequestOptions? options = null, CancellationToken cancellationToken = default)

Retires the current entry and resumes the top retained entry.

BackToAsync

public ValueTask<NavigationResult<TContent>> BackToAsync(NavigationEntryId entry, NavigationRequestOptions? options = null, CancellationToken cancellationToken = default)

Retires every entry above entry and resumes it.

ClearAsync

public ValueTask<NavigationResult<TContent>> ClearAsync(NavigationRequestOptions? options = null, CancellationToken cancellationToken = default)

Retires every entry. The region becomes empty.

ClearHistoryAsync

public ValueTask<NavigationResult<TContent>> ClearHistoryAsync(NavigationRequestOptions? options = null, CancellationToken cancellationToken = default)

Retires every retained entry. The current entry stays.

PushAsync

public ValueTask<NavigationResult<TContent>> PushAsync(INavigationTarget<TContent> target, NavigationRequestOptions? options = null, CancellationToken cancellationToken = default)

Pushes a new entry. The current entry is retained.

PushAsync

public ValueTask<NavigationResult<TContent>> PushAsync<TViewModel>(NavigationRequestOptions? options = null, CancellationToken cancellationToken = default) where TViewModel : class, TContent

Pushes a new TViewModel that the navigator constructs and owns, like NavigationRegion.PushAsync with NavigationTarget.Create.

Type parameters

TViewModel

The content type to construct; its constructor parameters come from the entry's service provider.

PushAsync

public ValueTask<NavigationResult<TContent>> PushAsync<TViewModel, TInput>(TInput input, NavigationRequestOptions? options = null, CancellationToken cancellationToken = default) where TViewModel : class, TContent, INavigationInput<TInput>

Pushes a new TViewModel that the navigator constructs, owns and initializes with input, like NavigationTarget.Create.

Type parameters

TViewModel

The content type to construct; its constructor parameters come from the entry's service provider.

TInput

The input type.

Parameters

input

The input passed to the content's typed hooks: INavigationInitialize.InitializeAsync and INavigationArrived.OnArrivedAsync.

options

The request's options.

cancellationToken

Cancels the request before it commits.

PushForResult

public NavigationResultRequest<TContent, TResult> PushForResult<TResult>(INavigationTarget<TContent> target, NavigationRequestOptions? options = null, CancellationToken cancellationToken = default)

Pushes a new entry like NavigationRegion.PushAsync and waits for a typed result from it. The entry returns its result with NavigationEntryContext.CompleteAsync, which goes back from it; when it was pushed onto an empty region, the region becomes empty again.

Type parameters

TResult

The result type.

Remarks

NavigationResultRequest.Completion is dismissed when the push does not commit, when the entry retires without completing, and when the navigator closes. Cancelling cancellationToken before the commit gives the usual NavigationRejection.Cancelled outcome. After the commit it dismisses the request at once and goes back from the entry if it is still current; that back transition is not awaited, and a rejection or supersession of it is logged (1065, 1066). A departure guard that awaits a result in another region should pass its own token, so supersession and window close dismiss the request.

PushForResult

public NavigationResultRequest<TContent, TResult> PushForResult<TViewModel, TResult>(NavigationRequestOptions? options = null, CancellationToken cancellationToken = default) where TViewModel : class, TContent

Pushes a new TViewModel that the navigator constructs and owns, and waits for a typed result from it, like NavigationRegion.PushForResult with NavigationTarget.Create. For a target with input, pass NavigationTarget.Create to NavigationRegion.PushForResult.

Type parameters

TViewModel

The content type to construct; its constructor parameters come from the entry's service provider.

TResult

The result type.

ReplaceAsync

public ValueTask<NavigationResult<TContent>> ReplaceAsync(INavigationTarget<TContent> target, NavigationRequestOptions? options = null, CancellationToken cancellationToken = default)

Retires the current entry and makes a new entry current. History is unchanged.

ReplaceAsync

public ValueTask<NavigationResult<TContent>> ReplaceAsync<TViewModel>(NavigationRequestOptions? options = null, CancellationToken cancellationToken = default) where TViewModel : class, TContent

Replaces the current entry with a new TViewModel that the navigator constructs and owns, like NavigationRegion.ReplaceAsync with NavigationTarget.Create.

Type parameters

TViewModel

The content type to construct; its constructor parameters come from the entry's service provider.

ReplaceAsync

public ValueTask<NavigationResult<TContent>> ReplaceAsync<TViewModel, TInput>(TInput input, NavigationRequestOptions? options = null, CancellationToken cancellationToken = default) where TViewModel : class, TContent, INavigationInput<TInput>

Replaces the current entry with a new TViewModel that the navigator constructs, owns and initializes with input.

Type parameters

TViewModel

The content type to construct; its constructor parameters come from the entry's service provider.

TInput

The input type.

Parameters

input

The input passed to the content's typed hooks: INavigationInitialize.InitializeAsync and INavigationArrived.OnArrivedAsync.

options

The request's options.

cancellationToken

Cancels the request before it commits.

ResetAsync

public ValueTask<NavigationResult<TContent>> ResetAsync(INavigationTarget<TContent> target, NavigationRequestOptions? options = null, CancellationToken cancellationToken = default)

Retires every entry and makes a new entry the root.

ResetAsync

public ValueTask<NavigationResult<TContent>> ResetAsync<TViewModel>(NavigationRequestOptions? options = null, CancellationToken cancellationToken = default) where TViewModel : class, TContent

Retires every entry and makes a new TViewModel, which the navigator constructs and owns, the root, like NavigationRegion.ResetAsync with NavigationTarget.Create.

Type parameters

TViewModel

The content type to construct; its constructor parameters come from the entry's service provider.

ResetAsync

public ValueTask<NavigationResult<TContent>> ResetAsync<TViewModel, TInput>(TInput input, NavigationRequestOptions? options = null, CancellationToken cancellationToken = default) where TViewModel : class, TContent, INavigationInput<TInput>

Retires every entry and makes a new TViewModel, which the navigator constructs, owns and initializes with input, the root.

Type parameters

TViewModel

The content type to construct; its constructor parameters come from the entry's service provider.

TInput

The input type.

Parameters

input

The input passed to the content's typed hooks: INavigationInitialize.InitializeAsync and INavigationArrived.OnArrivedAsync.

options

The request's options.

cancellationToken

Cancels the request before it commits.

Start

public void Start(INavigationTarget<TContent> target)

Commits the root entry of a region created without an initial target, synchronously, like the initial target of RunicNavigator.CreateRegion. Call it once, where the root page exists, for example in the constructor of a window's ViewModel: Main.Start(NavigationTarget.Borrow<IPage>(list)).

Parameters

target

The root content.

Exceptions

ArgumentException

The target has input, was not created with NavigationTarget, or its content initializes asynchronously.

InvalidOperationException

The region already has its initial entry (it was created with one, or NavigationRegion.Start was called before), or it already received a navigation request.

ObjectDisposedException

The navigator is closed.

Remarks

The target follows the rules for initial targets: it has no input, and its content implements neither INavigationInitialize nor INavigationInitialize. Content that a Create target constructs can take its NavigationEntryContext as a constructor parameter.

Before the method returns, the entry's NavigationEntryContext.StateChanged and INavigationAware.OnNavigatedTo (with NavigationOperation.Reset), then the region's NavigationRegion.PropertyChanged, run on the caller's thread. Call it before the region is shared with other threads.

Unlike a navigation request, a failure throws: an exception from the target's factory or constructor propagates, and the region stays empty. Opened through IRunicWindowService, the window then fails to open.

ToString

public override string ToString()

Inherits documentation from Object.ToString.