Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 29, 2025

TrayMenu.Open() only built a flat menu structure, ignoring the Menu property on TrayMenuItem. This prevented creating multi-level context menus for the system tray icon.

Changes

  • User32.cs: Added MF_POPUP flag and AppendMenu overload accepting nint for submenu handles
  • TrayIconHost.cs: Extracted menu building into recursive BuildMenu helper that creates submenus when TrayMenuItem.Menu is populated

Usage

Menu = new TrayMenu
{
    new TrayMenuItem
    {
        Header = "Settings",
        Menu = new TrayMenu
        {
            new TrayMenuItem { Header = "Option 1", Command = Opt1Command },
            new TrayMenuItem
            {
                Header = "Advanced",
                Menu = new TrayMenu
                {
                    new TrayMenuItem { Header = "Sub-option A" },
                    new TrayMenuItem { Header = "Sub-option B" },
                }
            }
        }
    },
    new TrayMenuItem { Header = "Exit", Command = ExitCommand }
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Inability to Create Nested Submenus using TrayIconHost</issue_title>
<issue_description>### Describe the bug

Attempting to implement nested submenus (submenus within an existing submenu) for the system tray icon context menu fails; only the first level of submenus can be successfully displayed. Is this a known limitation of the current implementation, or is there a specific method/pattern required to successfully implement nested submenus that I might be missing?

To Reproduce

using the example code:

using Win32Icon icon = new(ResourcesProvider.GetStream(new Uri("pack://application:,,,/Wpf.Ui.Test;component/Resources/Images/ProfilePicture.ico")));

 _iconHost = new TrayIconHost()
 {
     ToolTipText = "Wpf.Ui.Test",
     Icon = icon.Handle,
     Menu =
     [
         new TrayMenuItem()
         {
             Header = Version,
             IsEnabled = false,
         },
         new TraySeparator(),
         new TrayMenuItem()
         {
             Header = "Restart",
             Command = RestartCommand,
         },
         new TrayMenuItem()
         {
             Header = "Exit",
             Command = ExitCommand,
         }
     ],
 };

I can't create nested submenus

Expected behavior

The nested submenu (Level 2) should appear when the user hovers over the Level 1 submenu item in the system tray context menu, allowing for a structured menu hierarchy.

Screenshots

No response

OS version

Windows 10 19045.5011

.NET version

8

WPF-UI NuGet version

4.0.3.6

Additional context

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Nov 29, 2025
Co-authored-by: emako <24737061+emako@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix inability to create nested submenus using TrayIconHost Add support for nested submenus in TrayIconHost Nov 29, 2025
Copilot AI requested a review from emako November 29, 2025 03:30
Copilot finished work on behalf of emako November 29, 2025 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inability to Create Nested Submenus using TrayIconHost

2 participants