public sealed class ViewRequest<T> A one-way request of a ViewModel to its web View, such as to focus a field, scroll a row into view, scroll to the top or show a toast. The ViewModel raises it without waiting for an answer; the page handles it with the generated client.requests.<name>.handle((input, { signal }) => …).
Type parameters
TThe request's input, a bridge value; use an empty record for a request without data.
Remarks
Expose it as a get-only property; the generated Bridge sends it to the pages that present the ViewModel, in both MVVM flavors (ReactiveUI and CommunityToolkit):
public ViewRequest<FocusTarget> Focus { get; } = new();
public ViewRequest<Toast> Notify { get; } = new(ViewRequestDelivery.Broadcast);
private void Add() { Items.Add(item); Focus.Raise(new FocusTarget(item.Id)); }A request is not state: a snapshot or a reconnect never repeats it, and it never reaches another window. ViewRequestDelivery.Drop and ViewRequestDelivery.NextMounted requests that a command raises reach only the invoking page's connection; a ViewRequestDelivery.Broadcast reaches every connection of the window. The page handles it once it has rendered the state that includes everything the ViewModel changed before raising it, so a handler finds the new row in the page. A page or host of an earlier release ignores requests.
Constructors
ViewRequest
public ViewRequest(ViewRequestDelivery delivery = ViewRequestDelivery.Drop) Creates a view request.
Parameters
deliveryWhere the request goes; by default
ViewRequestDelivery.Drop.
Exceptions
ArgumentOutOfRangeExceptiondeliveryis not a defined value.
Properties
Methods
Raise
public void Raise(T input) Sends the request to the pages that present the ViewModel, by its ViewRequest.Delivery, and returns at once.
Parameters
inputThe request's input.
Exceptions
ArgumentExceptioninputcannot be encoded or exceeds the window's input limit.
Remarks
Call it from any thread, usually in a command. What the ViewModel changed before the call is published first, so the page handles the request after it rendered those changes.