public interface IRunicWindowResult<in TResult> Completes the Window that the scope belongs to with a result, for a Window opened with IRunicWindowService.OpenForResultAsync. Take it in the constructor of the Window's ViewModel:
public sealed partial class ChooseAccountViewModel(IRunicWindowResult<Account> result) : ObservableObject
{
[RelayCommand]
private async Task ChooseAsync(Account account) => await result.CompleteAsync(account);
}Type parameters
TResultThe result's type, as the open named it.
Remarks
RunicWindowServiceCollectionExtensions.AddRunicWindowService registers it per scope. A test that builds such a ViewModel by hand passes its own implementation, or uses RunicWindowTestHost.CreateWindow.
Methods
CompleteAsync
ValueTask<bool> CompleteAsync(TResult result, CancellationToken cancellationToken = default) Completes the Window with result and starts closing it without asking its close guard, as IRunicWindow.CloseAsync does: the application has decided.
Parameters
resultThe result the opener receives.
cancellationTokenCancels the request before the result is set.
Returns
true when this call set the result; false when the Window already completed or closed, and the result is dropped.
Exceptions
InvalidOperationExceptionThe Window was not opened for a result of this type, or the service was resolved outside a Window's scope.
Remarks
It returns once the result is set; the opener receives it when the Window has closed. The close lets accepted operations, such as the command that called this method, finish for up to 5 seconds, so that command completes normally; operations still running then are cancelled.