NavigationEntryContext class

Namespace Runic.Navigation in Runic.Navigation 0.23.0

public sealed class NavigationEntryContext

Gives an entry's content its identity, state, retirement signal, model context and late-completion operations.

Remarks

Content that the navigator creates takes its context as a constructor parameter: with NavigationTarget.Create and the region methods that wrap it, or from the factory of NavigationTarget.Create; the typed-input forms and initial targets included. Only the content receives it: a service resolved from the container can't, and resolving it there fails. Content created with NavigationTarget.Own or NavigationTarget.Borrow receives it in INavigationInitialize.InitializeAsync.

Properties

Id

public NavigationEntryId Id { get; }

Gets the entry's id.

ModelContext

public IRunicModelContext ModelContext { get; }

Gets the model context that commits navigation state.

Retirement

public CancellationToken Retirement { get; }

Gets a token that is cancelled when the entry starts retiring.

Services

public IServiceProvider Services { get; }

Gets the entry's service provider: its own service scope when the navigator created one (RunicNavigatorOptions.CreateEntryScopes), otherwise the navigator's RunicNavigator.Services, otherwise an empty provider. It is the provider NavigationEntry.Services returns. After an entry with its own scope retires, resolving from it throws ObjectDisposedException.

State

public NavigationEntryState State { get; }

Gets the entry's current state. It is NavigationEntryState.Pending while the content is constructed and initialized, and changes in the model turn that commits a change (see NavigationEntryContext.StateChanged).

Methods

BackAsync

public ValueTask<NavigationResult<object>> BackAsync(CancellationToken cancellationToken = default)

Goes back from this entry. The request expects this entry to be current, so a retained or retired entry receives NavigationRejection.NotCurrent.

CompleteAsync

public ValueTask<NavigationResult<object>> CompleteAsync<TResult>(TResult result, CancellationToken cancellationToken = default)

Completes the NavigationRegion.PushForResult request that pushed this entry and goes back from it, like NavigationEntryContext.BackAsync. When this entry is the region's only entry, going back leaves the region empty. The request's completion becomes Completed with result only if that back transition commits; otherwise the entry stays current, the request stays open, and the call can be repeated. When the request was already dismissed, the entry still goes back and the result is dropped.

Type parameters

TResult

The request's result type, or any type whose value is a result-type value at run time, such as Boolean for a bool? request or Int32 for an Object request.

Parameters

result

The result.

cancellationToken

Cancels the back transition before it commits.

Exceptions

InvalidOperationException

The entry was not pushed with PushForResult, or result is not a value of its result type.

DismissAsync

public ValueTask<NavigationResult<object>> DismissAsync(CancellationToken cancellationToken = default)

Leaves this entry without a result. What happens depends on the entry's state:

Parameters

cancellationToken

Cancels the Back before it commits. The dismissal of the request is not undone.

Events

StateChanged

public event EventHandler<NavigationEntryStateChangedEventArgs>? StateChanged

Raised once for each change of NavigationEntryContext.State, inside a model turn: the commit turn of a navigation; the turn that clears the entry's region when it closes; and, for a pending entry whose transition did not commit, a turn posted when it retires. When an initial target becomes current, RunicNavigator.CreateRegion raises it before it returns, on the caller's thread. A change that happens after the model context closed is not raised.

Remarks

In the commit turn it is raised after the new navigation state is applied and before the regions raise PropertyChanged, together with INavigationAware (see there for the order). Each handler is called separately; one that throws is logged (event 1075) and does not skip the others or undo the change.