ReactiveNavigationRegionGuard class

Namespace Runic.Navigation.ReactiveUI in Runic.Navigation.ReactiveUI 0.23.0

public static class ReactiveNavigationRegionGuard

Creates an INavigationRegionGuard that asks through a ReactiveUI interaction.

Methods

WithInteraction

public static INavigationRegionGuard WithInteraction<TPrompt>(IInteraction<TPrompt, bool> interaction, Func<NavigationRegionDeparture, TPrompt> prompt, Func<NavigationRegionDeparture, bool> hasUnsavedChanges, Action? discard = null)

Creates a region guard whose question is interaction.Handle(prompt(departure)), for a question about a whole region rather than one page, such as unsaved work anywhere in a window: a handler that sets true lets the transition depart, false rejects it as NavigationRejection.Guard. Register the result with NavigationRegion.AddDepartureGuard or RunicNavigator.AddDepartureGuard; their NavigationRegionGuardOptions decide when it is asked.

Type parameters

TPrompt

The interaction's input.

Parameters

interaction

The interaction, typically a get-only property of the shell ViewModel.

prompt

Creates the question's input for the departure. It is called inside a model turn, once per question.

hasUnsavedChanges

Returns whether the departure would lose changes. It is called inside a model turn.

discard

Discards the changes. It runs in the commit turn of a confirmed transition.

Remarks

Nothing is asked when hasUnsavedChanges returns false. After a yes, discard runs in the commit turn if the transition commits (NavigationRegionDeparture.OnCommitted), and not at all if it does not. Like any region guard, the guard is asked again when a transition reruns.

The question is asked as ReactiveLeaveConfirmation.WithInteraction asks it: outside model turns, on the thread the guard runs on; a superseded, cancelled or closed transition disposes the Handle subscription and the guard returns at once; and the transition fails closed when no handler answers, with NavigationPhase.Guarding and event 1060 (NavigationGuardFailed), as when a handler throws. A .NET handler registered on the interaction answers, latest first, as in ReactiveUI.