Class SwapContentHost
- Namespace
- SharpConsoleUI.Flows
- Assembly
- SharpConsoleUI.dll
An opt-in IFlowHost that presents every step in ONE reused modal window, swapping the window's content per step instead of opening a fresh window each time. This gives a seamless wizard experience (no open/close flicker between steps), in contrast to the framework-default ModalWindowHost (a fresh modal per step).
public sealed class SwapContentHost : IFlowHost, IDisposable
- Inheritance
-
SwapContentHost
- Implements
- Inherited Members
- Extension Methods
Remarks
The window is created lazily on the FIRST PresentAsync<TResult>(IFlowStepContent<TResult>, FlowChrome, CancellationToken) call and reused on every subsequent call: each step calls ClearControls(), re-titles the window, and adds the SAME canonical three-band surface that ModalWindowHost builds (SharpConsoleUI.Flows.IFlowChromeBands → top/body/bottom; else body + a sticky-bottom right-aligned toolbar from Buttons).
Resolution paths mirror ModalWindowHost exactly (whichever fires first wins
via TrySetResult): a host button click resolves with that button's verdict; the content
completing its own Completion resolves Next (gated on
status so faults/cancellations are not masked); token cancellation resolves Cancel; user dismissal
of the window (Esc / title-bar close) resolves the CURRENT step as Cancel.
The window stays open BETWEEN steps and is closed when the host is disposed, when the user
dismisses it, or when a presentation's token cancels. Dispose the host to tear the window down on
normal completion: Run<T>(ConsoleWindowSystem, Window?, Func<FlowContext, Task<T>>, IFlowHost?, CancellationToken) and the wizard Run dispose the host in their
finally when it is IDisposable. Use via using when driving steps
directly.
Constructors
SwapContentHost(ConsoleWindowSystem, Window?)
Initializes a new SwapContentHost.
public SwapContentHost(ConsoleWindowSystem ws, Window? parent)
Parameters
wsConsoleWindowSystemThe window system to present steps in.
parentWindowOptional parent window; when provided the reused modal is modal to it.
Methods
Dispose()
Closes the reused window (idempotent, marshalled to the UI thread). Call this when the flow is
done so the seamless host does not leak its window. Run<T>(ConsoleWindowSystem, Window?, Func<FlowContext, Task<T>>, IFlowHost?, CancellationToken) and the wizard
Run invoke this automatically in their finally when the host is the seamless host.
public void Dispose()
PresentAsync<TResult>(IFlowStepContent<TResult>, FlowChrome, CancellationToken)
Presents content using chrome and resolves to its outcome.
public Task<FlowStepOutcome<TResult>> PresentAsync<TResult>(IFlowStepContent<TResult> content, FlowChrome chrome, CancellationToken ct)
Parameters
contentIFlowStepContent<TResult>The step body to present.
chromeFlowChromeChrome hints (title, size, step indicator, button row).
ctCancellationTokenCancellation token; when tripped the step resolves with Cancel.
Returns
- Task<FlowStepOutcome<TResult>>
A task completing with the step's FlowStepOutcome<TResult>: the content value plus the navigation verdict (or
(default, Cancel)on dismiss/cancellation).
Type Parameters
TResultThe content's result type.