Class RunnableWrapper<TView, TResult>
Wraps any View to make it runnable with a typed result without adding dialog buttons.
public class RunnableWrapper<TView, TResult> : Runnable<TResult>, IDisposable, ISupportInitializeNotification, ISupportInitialize, IRunnable<TResult>, IRunnable where TView : View, new()
Type Parameters
TViewThe type of view being wrapped. Must have a parameterless constructor.
TResultThe type of result data returned when the session completes.
Important: Use nullable types (e.g.,
DateTime?,Color?) so that null can indicate cancellation.
- Inheritance
-
Runnable<TResult>RunnableWrapper<TView, TResult>
- Implements
-
IRunnable<TResult>
- Inherited Members
- Extension Methods
Examples
// Wrap a DatePicker for inline use
RunnableWrapper<DatePicker, DateTime> wrapper = new ()
{
Title = "Select a Date",
ResultExtractor = dp => dp.Value
};
app.Run (wrapper);
if (wrapper.Result is { } date) Console.WriteLine (date);
Remarks
Unlike Prompt<TView, TResult>, this class does not add Ok/Cancel buttons. The wrapped view is responsible for setting Result and calling RequestStop() when the user accepts.
Use ResultExtractor to automatically extract the result when the view raises Accept.
Constructors
- RunnableWrapper()
Initializes a new instance of RunnableWrapper<TView, TResult> with a new instance of the view.
- RunnableWrapper(TView)
Initializes a new instance of RunnableWrapper<TView, TResult> with a specified view instance.
Properties
- ResultExtractor
Gets or sets the function that extracts the result from the wrapped view.
Methods
- GetWrappedView()
Gets the wrapped view.
- OnAccepting(CommandEventArgs)
Called when the user is accepting the state of the View and the Accept has been invoked. Set CommandEventArgs.Handled to true and return true to indicate the event was handled and processing should stop.