MenuFlyoutItem command binding not working in submenu items
See original GitHub issueDescription
MenuFlyoutItem command binding does not appear to work in the case below. This is similar to https://github.com/dotnet/maui/issues/5382, but that issue is closed.
A workaround at https://github.com/dotnet/maui/issues/5382 is mentioned and works as shown below. Should the NON WORKING EXAMPLE work without the 5382 workaround?
For example, I would expect the DoSomethingCommand to run below, but it only works if I modify the code below to use the workaround.
NON WORKING EXAMPLE `<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:viewmodels="clr-namespace:MauiApp1.ViewModel" x:Class="MauiApp1.MainPage" x:DataType="viewmodels:MainPageViewModel" x:Name="thisMenuBarWorkaround">
<ContentPage.BindingContext>
<viewmodels:MainPageViewModel/>
</ContentPage.BindingContext>
<ContentPage.MenuBarItems>
<MenuBarItem Text="File">
<MenuFlyoutSubItem Text="Open">
<MenuFlyoutItem Text="Open Do Something..."
Command="{Binding DoSomethingCommand}"/>
</MenuFlyoutSubItem>
</MenuBarItem>
</ContentPage.MenuBarItems>
</ContentPage>`
WORKING EXAMPLE USING WORKAROUND `<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:viewmodels="clr-namespace:MauiApp1.ViewModel" x:Class="MauiApp1.MainPage" x:DataType="viewmodels:MainPageViewModel" x:Name="thisMenuBarWorkaround">
<ContentPage.BindingContext>
<viewmodels:MainPageViewModel/>
</ContentPage.BindingContext>
<ContentPage.MenuBarItems>
<!--https://github.com/dotnet/maui/issues/5382 workaround-->
<MenuBarItem Text="File"
BindingContext="{Binding Path=BindingContext,
Source={x:Reference thisMenuBarWorkaround}}">
<MenuFlyoutSubItem Text="Open">
<MenuFlyoutItem Text="Open Do Something..."
Command="{Binding DoSomethingCommand}"/>
</MenuFlyoutSubItem>
</MenuBarItem>
</ContentPage.MenuBarItems>
</ContentPage>`
VIEWMODEL
using CommunityToolkit.Mvvm.Input;
namespace MauiApp1.ViewModel;
public partial class MainPageViewModel
{
[RelayCommand]
public static void DoSomething()
{
// This point is never hit without workaround
return;
}
Steps to Reproduce
- Load github example below and run solution.
- Note that the menu item will not reach the ViewModel command
Link to public reproduction project repository
https://github.com/jeff922/MauiMenuTest
Version with bug
7.0 Release Candidate 2
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
.NET 7.0.100-rc.2.22477.23 and Microsoft Visual Studio Community 2022 (64-bit) - Preview Version 17.4.0 Preview 3.0
Did you find any workaround?
Workaround mentioned in https://github.com/jeff922/MauiMenuTest.
Relevant log output
No response
Issue Analytics
- State:
- Created a year ago
- Comments:6 (2 by maintainers)

Top Related StackOverflow Question
@PureWeen Thanks. I updated VS to Preview 4 and this fixed the issue
Thank you for following up @jeff922 !!