CommunityToolkit / dotnet

.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
https://docs.microsoft.com/dotnet/communitytoolkit/?WT.mc_id=dotnet-0000-bramin
Other
3.07k stars 299 forks source link

RelayCommand not found when binding from sub menu items #640

Closed Symbai closed 1 year ago

Symbai commented 1 year ago

Describe the bug

RelayCommand is not working in WPF app when binding is from a sub menu item.

Regression

No response

Steps to reproduce

.NET 7, WPF app, Toolkit version 8.1.0

In designer:

<MenuItem Header="MenuItem with a sub menu item">
    <MenuItem Command="{Binding MyCommand}" Header="This is a sub menu item" />
</MenuItem>
<MenuItem Command="{Binding MyCommand}" Header="This is NOT a sub menu item" />

In your view model:

[RelayCommand]
public void MyCommand() {
    MessageBox.Show("Hi!");
}

Expected behavior

Clicking on the sub menu item should raise MyCommand command but it does not. Clicking on the menu item which is NOT a sub menu item, the command is raised.

Screenshots

No response

IDE and version

VS 2022 Preview

IDE version

No response

Nuget packages

Nuget package version(s)

8.1.0

Additional context

No response

Help us help you

No, just wanted to report this