question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Unable to make use of BindCommand method on MenuFlyoutItem object (Desktop menu)

See original GitHub issue

Description

Getting this exception message when the application is launched with the BindCommand method that is added to the MenuFlyoutItem object

No command + command parameter properties are registered for BindableObject type Microsoft.Maui.Controls.MenuFlyoutItem Register command + command parameter properties for this BindableObject type

After this exception, have tried to register the command using the DefaultBindableProperties.RegisterForCommand method.

But it resulted in a different exception with the below message (as MenuFlyoutItem inherits from MenuItem):

An item with the same key has already been added. Key: Microsoft.Maui.Controls.MenuItem

Stack Trace

Link to Reproduction Sample

https://github.com/egvijayanand/dotnet-maui-samples

Solution name: MenuApp (Made available under the src folder)

The page that is causing this exception is available in the MenuPageCS.cs

Steps to Reproduce

  1. Clone the repository
  2. Navigate to the src folder
  3. Open the MenuApp solution
  4. Set the instance of MenuPageCS as the Startup page in App.xaml.cs

Expected Behavior

The command is expected to bound to the MenuFlyoutItem object and invoke the associated action.

Actual Behavior

Ends in an exception.

Basic Information

  • Version with issue: 1.0.0
  • Last known good version: NA
  • IDE: VS2022 17.3.0 Preview 3.0
  • Platform Target Frameworks:
    • iOS: NA
    • Android: NA
    • UWP: net6.0-windows10.0.19041.0 - running on Windows 11
    • MacCatalyst - Haven’t tried on it due to infra constraint.
  • Android Support Library Version:
  • NuGet Packages:
  • Affected Devices:

Workaround

The event handler with the Invoke API works for now. Only Command is having the issue.

Reproduction imagery

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
egvijayanandcommented, Jul 15, 2022

Seems like the behavior is not consistent in XAML too, reference binding works but relative source binding fails.

Moreover, there is already an open issue (#5382) in the MAUI repo itself for Menu Commanding.

I think that is what influences here as well, let’s wait for it to get addressed and revisit this, if necessary.

1reaction
brminnickcommented, Jul 14, 2022

Ah - apologies! I see now that we’re testing MenuFlyoutItem. I’m able to reproduce + confirm the bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Command bound with MenuFlyoutItem is not getting ...
[Bug] Unable to make use of BindCommand method on MenuFlyoutItem object (Desktop menu) CommunityToolkit/Maui.Markup#82.
Read more >
Can't add MenuFlyoutItem to MenuFlyoutSubItem at runtime
I have a UIElement (such as a Button ) with a MenuFlyout set as its ContextFlyout . Whichever menu items / sub menu...
Read more >
Windows Phone 8.1 - Menu flyout item click command c# - ...
The OpenMenuFlyoutAction which implements DependencyObject and IAction to open the MenuFlyout by using the Execute method on the IAction ...
Read more >
[UWP] Can't launch Flyout using click event attached to ...
Hi, I'm trying to launch a Flyout in which I collect data from user. The idea is that the user click on an...
Read more >
MenuFlyoutItem Class (Windows.UI.Xaml.Controls)
Use a Flyout control to display single items and a MenuFlyout control to show a menu of items. ... Gets or sets the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found