public sealed class ViewQuestion<TInput, TOutput> A question a ViewModel asks its web View and waits for, such as a confirmation, in either MVVM flavor. It is the flavor-neutral counterpart of a ReactiveUI Interaction<TInput, TOutput>: on the page it is the generated client.interactions.<name>.handle((input, { signal }) => answer).
Type parameters
TInputThe question, a bridge value.
TOutputThe answer, a bridge value.
Remarks
Expose it as a get-only property. ViewQuestion.AskAsync asks the page in the same scopes as an interaction: inside a command that a page invoked, that page's presentation; in the window scope (a close decision, a menu-bar command, RunicInteractionInvocation.EnterWindow), the one presentation of the window that handles it. When no page can answer, it runs the fallback, or fails with RunicInteractionUnhandledException.
public ViewQuestion<DiscardRequest, bool> ConfirmDiscard { get; } = new((_, _) => ValueTask.FromResult(false));
[RelayCommand]
private async Task DiscardAsync(CancellationToken token)
{
if (await ConfirmDiscard.AskAsync(new DiscardRequest(Title), token)) Reset();
}Constructors
ViewQuestion
public ViewQuestion(Func<TInput, CancellationToken, ValueTask<TOutput>>? fallback = null, TimeSpan? timeout = null) Creates a view question.
Parameters
fallbackAnswers when no page can; without one, an unanswered question fails.
timeoutHow long a page may take to answer: at most 24 hours, by default two minutes, or
Timeout.InfiniteTimeSpanfor no deadline, as for a question a person answers. Without a deadline the question still ends whenViewQuestion.AskAsync's token or the asking command is cancelled, when the page unmounts or disconnects and when the Window closes. A page of@runic-artifex/viewsbefore 0.23 aborts its handler after ten minutes regardless.
Exceptions
ArgumentOutOfRangeExceptiontimeoutis not positive or exceeds 24 hours, and is notTimeout.InfiniteTimeSpan.
Properties
Timeout
public TimeSpan? Timeout { get; } How long a page may take to answer, Timeout.InfiniteTimeSpan for no deadline, or null for the default of two minutes.
Methods
AskAsync
public Task<TOutput> AskAsync(TInput input, CancellationToken cancellationToken = default) Asks the page and returns its answer, or the fallback's when no page can answer.
Parameters
inputThe question.
cancellationTokenCancels the question; the page's handler is aborted.
Returns
The answer.
Exceptions
RunicInteractionUnhandledExceptionNo page can answer and there is no fallback.
RunicInteractionCancelledExceptionThe page cancelled, or its presentation closed.
RunicInteractionTimeoutExceptionThe page did not answer within
ViewQuestion.Timeout.RunicInteractionOutputExceptionThe page's answer does not match the contract.
OperationCanceledExceptioncancellationTokenwas cancelled.