Build with XuiView Markdown

Overlays and additional windows

Show a small note near its trigger without taking the user away from the page. Use IOverlay for content that belongs inside the current window; use a separate desktop window only when the task needs independent window behavior.

using Xui.Core.Canvas;
using Xui.Core.Math2D;
using Xui.Core.UI;
using Xui.ToolKit.UI.Design;
using Xui.ToolKit.UI.Widgets;

public sealed class OverlayExample : Border
{
    private IOverlay? overlay;
    private readonly Button action;
    public OverlayExample()
    {
        action = new Button
        {
            Text = "Show a note",
            Margin = 24,
            Clicked = ShowNote
        };
        Content = new DesignSystemView(new VerticalStack { Content = [action] });
    }

    private void ShowNote()
    {
        overlay ??= GetService(typeof(IOverlay)) as IOverlay;
        if (overlay is null)
            return;
        var topLeft = action.LocalToGlobal(action.Frame.TopLeft);
        var anchor = new Rect(topLeft, action.Frame.Size);
        overlay.Show(new Border { BackgroundColor = new Color(0xEADCFBFF), Padding = 20, Content = new Label { Text = "Click outside to close.", FontFamily = "Inter", FontSize = 16 } }, anchor, PopupPlacement.Below, new Size(280, 100));
    }

    protected override void OnDeactivate()
    {
        overlay?.Dispose();
        overlay = null;
        base.OnDeactivate();
    }
}
Overlays and additional windows: initial rendered view
Overlays and additional windows · C# source · SVG · Open demo

Position an overlay

GetService(typeof(IOverlay)) resolves a window-owned overlay service through the view tree. Resolve it after the view is connected, such as in the click handler. Show accepts content, an anchor in window coordinates, a preferred placement, and an optional size.

The example maps the button's frame through LocalToGlobal. That matters when a control sits inside scrolling or transformed content. For this unrotated button, the frame size remains unchanged. A transformed rectangle needs all of its corners mapped if rotation or scaling changes its bounds.

The overlay clamps its position and size to the window's display area. Clicking outside dismisses it. Close() hides it explicitly, and Dispose() closes any visible content. The page disposes its handle on deactivation so a note does not linger over the next page.

An overlay is a separate subtree under the root. Do not assume it inherits a design-system provider placed only inside the original page. This example uses explicit Core colors and text; themed overlay widgets need their own provider or a shared provider reachable from their tree.

Choose the right surface

An in-window overlay cannot escape the owning window's bounds. The separate IPopup contract represents native popup behavior where implemented; do not assume every runtime supports a native popup because the contract exists. PopupEffect on IOverlay.Show is currently reserved rather than a guarantee of blur or dimming.

A second desktop Window has its own root and native lifetime. Create it from an appropriate service scope, call Show(), and close/dispose it with the page or operation that owns it. Do not dispose the main window's shared scope while closing a secondary window.

DemoApp's developer Clock page illustrates ownership: Open Clock creates the secondary window; Close Clock closes it; navigating away also closes it. Native browser and phone hosts are not interchangeable with desktop multi-window behavior.

For modal workflows, design focus entry, focus restoration, dismissal, and background interaction deliberately. Merely drawing a floating rectangle does not establish a complete accessible modal dialog.