MenuBarItem with no Items shows blank Dropdown
See original GitHub issueDescribe the bug
It’s sometimes desirable to have a top-level MenuBarItem
in a MenuBar
that contains no items and is just effectively a ‘button’. This is common in some apps for certain common functions or for a simple ‘Help’ or ‘About’ dialogs.
Steps to reproduce the bug
- Copy Keyboard accelerator example from XAML Controls Gallery into XAML Studio
- Add a blank MenuBarItem:
<muxc:MenuBarItem Title="View"/>
- Click on it, note: a blank menu drops down.
Expected behavior No Menu to drop-down, should only act as a button.
Screenshots
Full XAML Example
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d">
<muxc:MenuBar>
<muxc:MenuBarItem Title="File">
<MenuFlyoutItem Text="New">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control" Key="N"/>
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
<MenuFlyoutItem Text="Open...">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control" Key="O"/>
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
<MenuFlyoutItem Text="Save">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control" Key="S"/>
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
<MenuFlyoutItem Text="Exit">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control" Key="E"/>
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
</muxc:MenuBarItem>
<muxc:MenuBarItem Title="Edit">
<MenuFlyoutItem Text="Undo">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control" Key="Z"/>
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
<MenuFlyoutItem Text="Cut">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control" Key="X"/>
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
<MenuFlyoutItem Text="Copy">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control" Key="C"/>
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
<MenuFlyoutItem Text="Paste">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control" Key="V"/>
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
</muxc:MenuBarItem>
<muxc:MenuBarItem Title="View"/>
<muxc:MenuBarItem Title="Help">
<MenuFlyoutItem Text="About">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Modifiers="Control" Key="I"/>
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
</muxc:MenuBarItem>
</muxc:MenuBar>
</Page>
Version Info
NuGet package version: 2.3.191129002
Windows 10 version | Saw the problem? |
---|---|
Insider Build (xxxxx) | |
May 2020 Update (19041) | Yes |
November 2019 Update (18363) | |
May 2019 Update (18362) | |
October 2018 Update (17763) | |
April 2018 Update (17134) | |
Fall Creators Update (16299) | |
Creators Update (15063) |
Device form factor | Saw the problem? |
---|---|
Desktop | Yes |
Xbox | |
Surface Hub | |
IoT |
Additional context Related to gap for #2216
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:11 (10 by maintainers)
Top Results From Across the Web
What is the proper way to show blank menu item for ...
setting the MenuItem value to "" and primaryText to "" will make it invisible in the choices. I suggest you do this:
Read more >Dropdown menu appears blank
Hi. The menu at the top of my homepage has an issue where for the menu items that have a dropdown menu ('Studying'...
Read more >blank item in dropdown menu - Microsoft Power BI Community
Solved! Go to Solution. Labels: Labels: Need Help · Show and ...
Read more >How to detect a select menu is blank - Studio
I'm automating filling out a web form that has dynamic Select menus. One of these only populates when valid data is found. If...
Read more >Solved: Dropdown list value is blank when opening existing...
The only problem I ran into is when I'm going back to edit an existing item. The choices fields did not display/pull the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This would also match the behavior of WPF’s
Menu
\MenuItem
control:It’s important to note here that WinUI’s
MenuBarItem
currently does not have APIs to handle user input like aClick
event or aCommand
property like WPF’s MenuItem does. There is the inherited PointerPressed event fromUIElement
but that event is not raised for developers to use here.As such, if it’s agreed that it’s a valid use case to have a MenuBarItem act like a button (when there are no child items) it makes sense to me that we should also add APIs like a Click event or a Command property to the MenuBarItem then.
I will try to create the proposal this weekend though I’m not sure if every API of it can be added prior to WinUI going full open-source. The
Command
API for example can probably be best implemented by re-using internal WinUICommand
logic (used for other Command properties in WinUI) and, from what I can tell after doign a quick check, that logic is not available in WinUI 2.