Method RunView
RunView<TView, TResult>(IApplication, TView, Func<TView, TResult?>, Func<Exception, bool>?)
Runs any View as a runnable session, extracting a typed result via a function.
public static TResult? RunView<TView, TResult>(this IApplication app, TView view, Func<TView, TResult?> resultExtractor, Func<Exception, bool>? errorHandler = null) where TView : View
Parameters
appIApplicationThe application instance. Cannot be null.
viewTViewThe view to run as a blocking session. Cannot be null.
resultExtractorFunc<TView, TResult>Function that extracts the result from the view when stopping. Called automatically when the runnable session ends.
errorHandlerFunc<Exception, bool>Optional handler for unhandled exceptions during the session.
Returns
- TResult
The extracted result, or null if the session was canceled.
Type Parameters
TViewThe type of view to run.
TResultThe type of result data to extract.
Examples
var app = Application.Create();
app.Init();
// Run a TextField and get the entered text
var text = app.RunView(
new TextField { Width = 40 },
tf => tf.Text);
Console.WriteLine($"You entered: {text}");
// Run a ColorPicker and get the selected color
var color = app.RunView(
new ColorPicker(),
cp => cp.SelectedColor);
Console.WriteLine($"Selected color: {color}");
// Run a FlagSelector and get the selected flags
var flags = app.RunView(
new FlagSelector<SelectorStyles>(),
fs => fs.Value);
Console.WriteLine($"Selected styles: {flags}");
app.Shutdown();
Remarks
This method wraps the view in a RunnableWrapper<TView, TResult>, runs it as a blocking session, and returns the extracted result. The wrapper is NOT disposed automatically; the caller is responsible for disposal.
The result is extracted before the view is disposed, ensuring all data is still accessible.
Exceptions
- ArgumentNullException
Thrown if
app,view, orresultExtractoris null.
RunView<TView>(IApplication, TView, Func<Exception, bool>?)
Runs any View as a runnable session without result extraction.
public static TView RunView<TView>(this IApplication app, TView view, Func<Exception, bool>? errorHandler = null) where TView : View
Parameters
appIApplicationThe application instance. Cannot be null.
viewTViewThe view to run as a blocking session. Cannot be null.
errorHandlerFunc<Exception, bool>Optional handler for unhandled exceptions during the session.
Returns
- TView
The view that was run, allowing access to its state after the session ends.
Type Parameters
TViewThe type of view to run.
Examples
var app = Application.Create();
app.Init();
// Run a ColorPicker without automatic result extraction
var colorPicker = new ColorPicker();
app.RunView(colorPicker);
// Access the view's state directly
Console.WriteLine($"Selected: {colorPicker.SelectedColor}");
app.Shutdown();
Remarks
This method wraps the view in a RunnableWrapper<TView, TResult> and runs it as a blocking session. The wrapper is NOT disposed automatically; the caller is responsible for disposal.
Use this overload when you don't need automatic result extraction, but still want the view to run as a blocking session. Access the view's properties directly after running.
Exceptions
- ArgumentNullException
Thrown if
apporviewis null.