public static class ReactiveNavigationEntryExtensions Reacts to a NavigationEntryContext becoming current and being left, and completes, dismisses or closes it with ReactiveUI commands. Content takes its entry context as a constructor parameter.
Remarks
ReactiveNavigationEntryExtensions.WhenNavigatedTo and ReactiveNavigationEntryExtensions.WhenNavigatedFrom are built on NavigationEntryContext.StateChanged, so they run in the model turn that commits the change, at the same moment as INavigationAware. Navigation lifetime is not ReactiveUI activation: a retained entry stays alive while nothing presents it, and its View may deactivate and activate again when it returns.
The entry owns what these methods create: a ReactiveNavigationEntryExtensions.WhenNavigatedTo subscription ends, and a command is disposed, when the entry retires. Dispose either yourself only to stop it earlier.
Methods
CreateCloseCommand
public static ReactiveCommand<Unit, NavigationOutcome> CreateCloseCommand(this NavigationEntryContext entry, IObservable<bool>? canExecute = null, IScheduler? outputScheduler = null) Creates a command that goes back from the entry through its departure guards, with NavigationEntryContext.BackAsync, and outputs the NavigationOutcome. This is an editor's Close command: a guard, such as a leave confirmation, may veto it.
Parameters
entryThe entry context.
canExecuteThe command's availability, or
nullto always allow it.outputSchedulerThe scheduler of the command's output and
IsExecuting, ornullfor ReactiveUI's main-thread scheduler.
Returns
The command, which the entry disposes when it retires.
Remarks
A request pushed with NavigationRegion.PushForResult stays open on a veto, and ends Dismissed only when the Back commits.
CreateCompleteCommand
public static ReactiveCommand<Unit, NavigationOutcome> CreateCompleteCommand<TResult>(this NavigationEntryContext entry, Func<CancellationToken, Task<TResult>> produce, IObservable<bool>? canExecute = null, IScheduler? outputScheduler = null) Creates a command that produces a result with produce, then calls NavigationEntryContext.CompleteAsync with it, and outputs the NavigationOutcome of the Back it issues, which a Runic View can receive. This is a Save or OK command.
Type parameters
TResultThe result type of the request.
Parameters
entryThe entry context.
produceProduces the result, for example by saving. It receives the command's cancellation token.
canExecuteThe command's availability, or
nullto always allow it.outputSchedulerThe scheduler of the command's output and
IsExecuting, ornullfor ReactiveUI's main-thread scheduler, as inReactiveNavigationRegionExtensions.CreateBackCommand.
Returns
The command, which the entry disposes when it retires.
Remarks
The Back runs the entry's departure guards. A veto outputs NavigationOutcomeKind.Rejected, the entry stays current and the request stays open, so the command can run again. The caller of NavigationRegion.PushForResult receives the typed result only when the Back commits.
A failure of produce, or an entry that was not pushed with PushForResult, is reported on ThrownExceptions, like a cancellation of the command. A rejected, superseded or failed Back is its output.
CreateCompleteCommand
public static ReactiveCommand<TResult, NavigationOutcome> CreateCompleteCommand<TResult>(this NavigationEntryContext entry, IObservable<bool>? canExecute = null, IScheduler? outputScheduler = null) Creates a command that completes the entry's request with the command's input, through NavigationEntryContext.CompleteAsync, and outputs the NavigationOutcome of the Back it issues. This is a command such as a list's Pick, whose parameter is the result.
Type parameters
TResultThe result type of the request, and the command's input type.
Parameters
entryThe entry context.
canExecuteThe command's availability, or
nullto always allow it.outputSchedulerThe scheduler of the command's output and
IsExecuting, ornullfor ReactiveUI's main-thread scheduler.
Returns
The command, which the entry disposes when it retires.
Remarks
The semantics are those of the overload that produces the result: a guard veto leaves the entry current and the request open, and an entry that was not pushed with PushForResult is reported on ThrownExceptions.
CreateDismissCommand
public static ReactiveCommand<Unit, NavigationOutcome> CreateDismissCommand(this NavigationEntryContext entry, IObservable<bool>? canExecute = null, IScheduler? outputScheduler = null) Creates a command that leaves the entry without a result, through NavigationEntryContext.DismissAsync, and outputs the NavigationOutcome of the Back. This is a dialog's Cancel command.
Parameters
entryThe entry context.
canExecuteThe command's availability, or
nullto always allow it.outputSchedulerThe scheduler of the command's output and
IsExecuting, ornullfor ReactiveUI's main-thread scheduler.
Returns
The command, which the entry disposes when it retires.
Remarks
A request pushed with NavigationRegion.PushForResult ends Dismissed at once, before the entry's guards run; if a guard then vetoes the Back, the request stays dismissed and the entry stays current. Without a request, the command goes back from the entry.
WhenNavigatedFrom
public static IObservable<NavigationExit> WhenNavigatedFrom(this NavigationEntryContext entry) Observes the entry stopping being its region's current entry: a push retains it (NavigationDepartureKind.Retain), or a Back, BackTo, Replace, Reset, Clear or the close of its region retires it (NavigationDepartureKind.Retire). The sequence completes when the entry retires.
Parameters
entryThe entry context.
Remarks
Values arrive in the commit turn, with NavigationEntryContext.StateChanged and INavigationAware.OnNavigatedFrom. A retained entry that retires emits nothing more and completes. There is no initial value; a subscription to a retired entry completes at once.
WhenNavigatedTo
public static IDisposable WhenNavigatedTo(this NavigationEntryContext entry, Action<NavigationArrival, ContainerDisposable> onNavigatedTo) Calls onNavigatedTo each time the entry becomes its region's current entry: when the push, replace or reset that creates it commits, and each time a Back or BackTo resumes it. Each call receives a new disposable scope, which is disposed when the entry stops being current, whether it is retained or retires.
Parameters
entryThe entry context.
onNavigatedToReceives the arrival and the scope for subscriptions that end when the entry is left.
Returns
The subscription, which ends when the entry retires. Dispose it only to stop the calls earlier.
Remarks
The callback runs in the commit turn, with NavigationEntryContext.StateChanged, before the regions raise PropertyChanged; the scope is disposed in the turn that commits the departure. It must not block or await navigation. A callback that throws is logged by the navigator (event 1075); the scope it received is disposed when the entry is left, like any other.
Subscribe while the entry is pending, in the constructor or INavigationInitialize.InitializeAsync; a subscription made while the entry is current starts with its next arrival. When the entry's model context closed before the departure could be raised, the scope is disposed when the entry retires, outside a turn. Disposing the returned subscription disposes the current scope and stops further calls.