NavigationRegion<TContent> class

Namespace Runic.Navigation · Runic.Navigation 0.7.0-preview.5

public sealed class NavigationRegion<TContent> : INavigationRegion, INotifyPropertyChanged where TContent : class

Inherits or implements INavigationRegion, INotifyPropertyChanged.

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

CanGoBack

public bool CanGoBack { get; }

Gets whether a retained entry exists to go back to.

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.

IsTransitioning

public bool IsTransitioning { get; }

Gets whether a transition of this region is in flight.

public RunicNavigator Navigator { get; }

Gets the navigator that owns the region.

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, INavigationInitialize<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 INavigationInitialize.InitializeAsync.

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, INavigationInitialize<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 INavigationInitialize.InitializeAsync.

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, INavigationInitialize<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 INavigationInitialize.InitializeAsync.

options

The request's options.

cancellationToken

Cancels the request before it commits.

ToString

public override string ToString()

Inherits documentation from Object.ToString.

Events

PropertyChanged

public event PropertyChangedEventHandler? PropertyChanged

Raised inside a model turn after a commit, for NavigationRegion.Current, NavigationRegion.CurrentEntry, NavigationRegion.History, NavigationRegion.CanGoBack and NavigationRegion.IsTransitioning. Each handler is called separately; one that throws is logged and does not skip the others.