public sealed class NavigationSelection : INotifyPropertyChanged Which one of an owner's sibling regions is presented, such as the tab of a page whose tabs each keep their own stack. Changing it is a navigation transition: the current entries of the region left, and of the regions below them, depart as NavigationDepartureKind.Retain, and a veto keeps the selection.
Remarks
A selection change is admitted, guarded, superseded, cancelled and committed like a request of a region, with NavigationOperation.Select, and its outcome is returned, never thrown. It changes no stack and no entry's state: the region left keeps its entries, which stay NavigationEntryState.Active, and selecting it again presents the same entry. The regions stay the owner's: when the owner's entry retires, every entry of every region is asked as NavigationDepartureKind.Retire, whichever is selected, and the regions and the selection close.
Only RunicNavigator.CreateSelection creates selections, and members can be added to the class in a minor release.
Properties
Admission
public NavigationAdmission Admission { get; } Gets how the selection admits a request while an earlier one runs (NavigationSelectionOptions.Admission).
IsBusy
public bool IsBusy { get; } Gets whether a request of this selection has not completed: from its admission until its task completes, like NavigationRegion.IsBusy. A selection change doesn't make the region it leaves busy.
IsTransitioning
public bool IsTransitioning { get; } Gets whether a selection change is in flight: from a request's admission until its commit decision, like NavigationRegion.IsTransitioning. A selection change doesn't make the region it leaves transition.
Navigator
public RunicNavigator Navigator { get; } Gets the navigator that owns the selection and its regions.
Regions
public IReadOnlyList<NavigationRegion> Regions { get; } Gets the regions to select from, in presentation order. The list is an immutable snapshot, replaced by NavigationSelection.Add and NavigationSelection.RemoveAsync.
Selected
public NavigationRegion? Selected { get; } Gets the presented region, or null only when NavigationSelection.Regions is empty.
SelectedIndex
public int SelectedIndex { get; } Gets the index of NavigationSelection.Selected in NavigationSelection.Regions, or -1 when NavigationSelection.Regions is empty.
Methods
Add
public void Add(NavigationRegion region) Appends region, a live region of this selection's navigator that the selection's owner owns and that is in no selection. When the selection was empty, the region becomes selected; nothing departs, and no guard is asked.
Parameters
regionThe region to append.
Exceptions
ArgumentExceptionThe region belongs to another navigator, is closed, has another owner, or is already in a selection.
ObjectDisposedExceptionThe selection or its navigator is closed.
Remarks
It supersedes no pending request of the selection. NavigationSelection.PropertyChanged is raised on the caller's thread before the method returns, so call it where the selection's state may change, for example in a command handler.
GetPath
public NavigationSelectionPath GetPath(INavigationRouteMap? routes = null) Gets the selection's regions, each with its entries and the regions below them, and the selected region, as a serializable path, like RunicNavigator.GetPath does for the whole navigator.
Parameters
routesThe route map, or
nullfor theINavigationRouteMapof the navigator's services.
Exceptions
InvalidOperationExceptionNo route map was passed or registered.
RemoveAsync
public ValueTask<NavigationResult<object>> RemoveAsync(NavigationRegion region, NavigationRequestOptions? options = null, CancellationToken cancellationToken = default) Removes region and closes it, as a document tab closes. Every entry of the region, and of the regions its owned content owns, is asked as NavigationDepartureKind.Retire, deepest first, with NavigationOperation.Clear, then the region and navigator guards. A veto changes nothing.
Parameters
regionThe region to remove, one of
NavigationSelection.Regions.optionsThe request's options.
cancellationTokenCancels the request before it commits.
Exceptions
ArgumentExceptionregionis not one ofNavigationSelection.Regions.
Remarks
It supersedes the pending requests of the region, as a parent's request does for a child region it closes, and the earlier pending requests of the selection. When the region was selected, the next region becomes selected, or the previous one when it was the last, or none when it was the only one; the newly selected region is not asked.
The commit closes the region, so later requests to it are NavigationRejection.Closed, replaces NavigationSelection.Regions, and retires the region's entries after the turn, as NavigationRegion.ClearAsync does. NavigationRequestOptions.ExpectedCurrent names the region's current entry. Committed.Current is the current entry of the region selected after the commit, and Committed.Retired holds the entries the removal retired.
RestoreAsync
public ValueTask<NavigationRestoreResult> RestoreAsync(NavigationSelectionPath path, NavigationRestoreOptions? options = null, CancellationToken cancellationToken = default) Rebuilds path in this selection, as RunicNavigator.RestoreAsync does: each region by position, regions beyond NavigationSelection.Regions from NavigationSelectionOptions.RestoreRegion, then the saved selection with NavigationSelection.SelectAsync.
Parameters
pathThe selection's path, such as one
NavigationSelection.GetPathreturned.optionsThe route map, what an unmapped entry does, and the bounds; the defaults without it.
cancellationTokenCancels the requests not yet committed; the restore then stops.
Exceptions
InvalidOperationExceptionNo route map was passed or registered.
OperationCanceledExceptioncancellationTokenwas cancelled.
SelectAsync
public ValueTask<NavigationResult<object>> SelectAsync(NavigationRegion region, NavigationRequestOptions? options = null, CancellationToken cancellationToken = default) Presents region. The current entry of the selected region, and the current entry of every region its content owns, deepest first, are asked as NavigationDepartureKind.Retain with NavigationOperation.Select, then the region guards that ask on retain and the navigator's. A veto keeps the selection. The commit changes only NavigationSelection.Selected and NavigationSelection.SelectedIndex.
Parameters
regionThe region to present, one of
NavigationSelection.Regions.optionsThe request's options.
cancellationTokenCancels the request before it commits.
Exceptions
ArgumentExceptionregionis not one ofNavigationSelection.Regions.
Remarks
Selecting the selected region while no request of the selection is pending commits at once. The entering region's entries are not asked or prepared. A later NavigationSelection.SelectAsync or NavigationSelection.RemoveAsync supersedes this request until it starts committing, and a commit in the region left, or in a region below it, while it asks supersedes it too; requests of the region left are neither superseded nor delayed.
NavigationRequestOptions.ExpectedCurrent names the current entry of the region left, at admission and at commit; NavigationRequestOptions.RetainView is ignored. Committed.Current is the current entry of the region selected after the commit, and Committed.Retired is empty. Compare the entry with the region's entries by NavigationEntry.Id.
WhenIdleAsync
public ValueTask WhenIdleAsync(CancellationToken cancellationToken = default) Completes when NavigationSelection.IsBusy is false: when no request of this selection is running. It doesn't wait for the requests of its regions.
Parameters
cancellationTokenStops waiting.
Remarks
A hook of a transition of this selection that awaits it deadlocks: the selection is busy while the hook runs.
Events
PropertyChanged
public event PropertyChangedEventHandler? PropertyChanged Raised inside a model turn for NavigationSelection.Regions, NavigationSelection.Selected, NavigationSelection.SelectedIndex, NavigationSelection.IsTransitioning and NavigationSelection.IsBusy; by NavigationSelection.Add, on the caller's thread. Each handler is called separately; one that throws is logged and does not skip the others.