H.NotifyIcon icon indicating copy to clipboard operation
H.NotifyIcon copied to clipboard

How can we keep Context Menu open? (WinUI)

Open tinmac opened this issue 7 months ago • 0 comments

I would like to keep the Flyout open if we click a MenuFlyoutItem, and only close with light dismiss.

I have done this in the past in a regular WinUI 3 project with args.Cancel = true; in Closing="MyMenuFlyout_Closing" (see below) but in this case MyMenuFlyout_Closing is not being called

How can this be done?

<notifyIcon:TaskbarIcon
    x:Name="TrayIconFoo"
    ContextMenuMode="SecondWindow"
    NoLeftClickDelay="True"
    ToolTipText="Foo me ToolTip">

    <notifyIcon:TaskbarIcon.IconSource>
        <notifyIcon:GeneratedIconSource Foreground="DarkSeaGreen" Text="❤️" />
    </notifyIcon:TaskbarIcon.IconSource>

    <notifyIcon:TaskbarIcon.ContextFlyout>

        <MenuFlyout x:Name="MyMenuFlyout" Closing="MyMenuFlyout_Closing">
            <MenuFlyoutItem Command="{x:Bind DoSomethingCommand}" Text="Test command" />
            <MenuFlyoutItem Text="Test" />
        </MenuFlyout>

    </notifyIcon:TaskbarIcon.ContextFlyout>

</notifyIcon:TaskbarIcon>```

    private void MyMenuFlyout_Closing(FlyoutBase sender, FlyoutBaseClosingEventArgs args)
    {
        Debug.WriteLine($"Flyout Closing called..."); // <<<< not being called 

        args.Cancel = true; // Usually prevents the flyout from closing
    }

tinmac avatar Jun 02 '25 15:06 tinmac