Table of Contents

Class Popover<TView, TResult>

Namespace
Terminal.Gui.App
Assembly
Terminal.Gui.dll

A generic popover that hosts a view and optionally extracts a typed result.

public class Popover<TView, TResult> : PopoverImpl, IDisposable, ISupportInitializeNotification, ISupportInitialize, IPopoverView, IPopover, IDesignable where TView : View, new()

Type Parameters

TView

The type of view being hosted. Must derive from View and have a parameterless constructor.

TResult

The type of result data extracted from the content view.

Important: Use nullable types (e.g., MenuItem?, int?, string?) so that null can indicate no result or cancellation. Using non-nullable value types (e.g., int) will return their default values, making it impossible to distinguish no result from a valid result.

Inheritance
Popover<TView, TResult>
Implements
Derived
Inherited Members
Extension Methods

Remarks

This class extracts the generic popover-hosting logic from PopoverMenu to enable reusable popover behavior for any view type.

IMPORTANT: Must be registered with Popover via Register(IPopoverView?) before calling MakeVisible(Point?, Rectangle?) or Show(IPopoverView?).

Key Features:

  • Generic content view hosting with automatic initialization
  • Result extraction via ResultExtractor or IValue<TValue>
  • Anchor-based positioning via Anchor function
  • Target view weak reference for command bubbling
  • Automatic command bridging from content view

Usage Example:

// Create a popover with a ListView that returns the selected string
var listView = new ListView { Source = new ListWrapper<string> (["Option 1", "Option 2"]) };
var popover = new Popover<ListView, string> { ContentView = listView };
popover.ResultExtractor = lv => lv.Source?.ToList ()?.ElementAtOrDefault (lv.SelectedItem) as string;

Application.Popover?.Register (popover); popover.MakeVisible ();

Constructors

Popover()

Initializes a new instance of the Popover<TView, TResult> class.

Popover(TView?)

Initializes a new instance of the Popover<TView, TResult> class with the specified content view.

Properties

ContentView

Gets or sets the content view hosted by this popover.

Result

Gets the result extracted from the content view when the popover was last closed.

ResultExtractor

Gets or sets the function that extracts the result from the content view.

Methods

Dispose(bool)

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

EnableForDesign<TContext>(ref TContext)

Enables the popover for use in design-time scenarios.

GetAdjustedPosition(View, Point)

Calculates an adjusted screen-relative position for the content view to ensure full visibility.

MakeVisible(Point?, Rectangle?)

Makes the popover visible and positions it based on Anchor or idealScreenPosition.

OnVisibleChanged()

Called when the Visible property has changed. Hides the popover via ApplicationPopover when becoming invisible.

SetPosition(Point?, Rectangle?)

Sets the position of the popover based on idealScreenPosition or anchor. The actual position may be adjusted to ensure full visibility on screen.

Events

ResultChanged

Raised when Result has changed.