Skip to content

ui::TrayIconOptions

Header: winui/ui/TrayIcon.hpp.

What a TrayIcon is created with: the icon, its hover text, its right-click menu and, optionally, the window a click opens next to it.

Example:

ui::Property<bool> quiet{false};

ui::TrayIcon tray{{
    .tool_tip = ui::bind(quiet, [](bool q) { return std::string{q ? "Timer (muted)" : "Timer"}; }),
    .icon     = ui::WindowIcon{.glyph = ui::IconGlyph{0xE916}},
    .menu     = {{.text = "Quit", .on_click = [] { ui::quit(); }}},
}};

Field Type Default
tool_tip Binding<std::string> The icon's hover text. The shell cuts it at 127 characters.
icon Binding<WindowIcon> The icon, drawn at the taskbar's small-icon size. ui::WindowIcon{.resource = "#101"} uses the executable's own icon resource. Empty shows the stock application icon.
icon_follows_taskbar_theme bool true A glyph icon on a transparent background is drawn black on a light taskbar and white on a dark one, whatever icon.foreground says, and redrawn when the user switches. Without it, a white glyph is invisible on a light taskbar.
menu std::vector<MenuItem> The right-click menu, top to bottom. It uses each item's text, on_click, command and enabled, separators, and the checked state of toggle and radio items. A toggle flips and a radio item unchecks its group as in any menu, and .checked = prop follows and writes the property. The app writes every item, including its way out ({.text = "Quit", .on_click = [] { ui::quit(); }}). Change it later with set_menu().
flyout Window* nullptr A window the app owns, opened next to the icon by a click and hidden by the next one. Create it with tray_flyout_options(). It must outlive the TrayIcon. With nullptr the icon has no flyout, and a click runs on_click.
flyout_max_height float 0.0f The flyout is as tall as its content, measured each time it opens, up to this many DIPs. Zero makes it as tall as the work area allows, less the margin.
flyout_margin float 12.0f Space between the flyout and the taskbar, and the screen edges beside it, in DIPs.
light_dismiss bool true Close the flyout when it stops being the active window, such as on a click anywhere else, Alt+Tab or the Win key. Otherwise it stays open until hide_flyout() or a second click on the icon.
flyout_background std::optional<Color> The flyout's fill. nullopt uses, under Fluent 2, the surface color of the system's own flyouts (#242424 dark, #F3F3F3 light), and under any other theme the era's popup surface.
on_click Callback<void()> A click or Enter on the icon, when there is no flyout.
on_notification_click Callback<void()> The user clicked the last notification, when it had no on_click of its own. Empty opens the flyout.