RunicPresentation class

Namespace Runic.Application.Views in Runic.Application.Views 0.23.0

public static class RunicPresentation

Renews and observes the presentations of a ViewModel in the pages of every window that presents it (Views protocol 4, features presentation-epoch/1 and presented/1).

Remarks

A ViewModel calls these with itself, from any thread, and needs no reference to its window. Pages and hosts of older releases do not use the features: RunicPresentation.Renew then only publishes the state again, and RunicPresentation.WaitForPresentedAsync returns false at its timeout.

Methods

Renew

public static void Renew(object viewModel)

Begins a new epoch of every route that presents viewModel, so the calls of its RunicPresentationScopedAttribute commands that a page sent for the previous state are superseded: they do not run and resolve with the current state.

Parameters

viewModel

The presented ViewModel.

Exceptions

ArgumentNullException

viewModel is null.

Remarks

Call it when the page shows something new without the ViewModel being presented again, such as a wizard's Next and Back, or when a cancelled dialog returns to its page. Scoped calls that arrive from now on are checked against the new epoch; the route publishes it as a full state with its next change, or the reply of the call that renewed it. A ViewModel that nothing presents is not affected: its next presentation begins an epoch anyway.

SyncNavigationPath

public static IDisposable SyncNavigationPath(NavigationRegion region, INavigationRouteMap? routes = null)

Makes region the window's path region (feature navigation-path/1): the route of its current entry is the page's route path, which a page that installs the navigation path keeps in its URL. A browser's Back and Forward and its address bar open a route path in the region with NavigationRouteOpen.BackToOrPush, through the departure guards; a refused change reverts the URL.

Parameters

region

A region of the window's navigator, typically its main region.

routes

The route map, or null for the INavigationRouteMap of the navigator's services.

Exceptions

InvalidOperationException

No route map was passed or registered, or the navigator already syncs another region.

Remarks

Call it once per window, for example in the constructor of the window's ViewModel. The window's Back (the mouse's Back button and Alt+Left, RunicNavigator.BackAsync) works without it. Dispose the result to stop.

WaitForPresentedAsync

public static ValueTask<bool> WaitForPresentedAsync(object viewModel, TimeSpan timeout, CancellationToken cancellationToken = default)

Waits until a page painted the state of viewModel that includes everything changed before this call, such as a result page that the application presents before it closes a window or exports a picture.

Parameters

viewModel

The ViewModel that a page presents or is about to present.

timeout

How long to wait, or Timeout.InfiniteTimeSpan.

cancellationToken

Stops the wait.

Returns

true when a page painted the state; false at the timeout, also when no page that uses presented/1 presents the ViewModel.

Exceptions

ArgumentNullException

viewModel is null.

ArgumentOutOfRangeException

timeout is negative and not infinite.

OperationCanceledException

cancellationToken was cancelled.

Remarks

The pending changes of every route that presents the ViewModel are published first, as before a call's reply. The wait completes with true once a page reports that it rendered one of those routes at that state or a later one. A ViewModel that no route presents yet counts with the first state of the first route that presents it, so Page = result; await RunicPresentation.WaitForPresentedAsync(result, …) works before the parent published Page.

A page that is hidden or minimized still reports, after its next timer. The timeout runs on the window's WindowContentSessionOptions.TimeProvider.