[Bug] Unable to make use of BindCommand method on MenuFlyoutItem object (Desktop menu)
See original GitHub issueDescription
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
- Clone the repository
- Navigate to the src folder
- Open the MenuApp solution
- 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:
- Created a year ago
- Comments:12
Top GitHub Comments
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.
Ah - apologies! I see now that we’re testing
MenuFlyoutItem
. I’m able to reproduce + confirm the bug.