Skip to content

How can we keep Context Menu open? (WinUI) #206

@tinmac

Description

@tinmac

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
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions