-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamically-created menu items with commands do not work #15858
Comments
The solution in #3100 still works, but your datatemplate content should not be menuitem. Otherwise your will have a menuitem inside menuitem. |
Thankyou for the reply, but as I already mentioned, the solution in #3100 does not work. Please try it out yourself and see. Here is the full axaml code for it so you can verify yourself that it truly does not work:
On your other point:
Notice The last thing you can do to convince yourself this is truly a bug is to remove the |
I tried and replied. You didnt set Classes for your Parent MenuItem, thats why it does not work for you. |
Apologies, this does appear to work. The reason I didn't include |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Describe the bug
A MenuItem with an ItemsSource specified, and which gets its Command from a property on an item in that collection, does not work. "Not work" meaning, the MenuItem is disabled regardless of what other settings you apply to the MenuItem in axaml or code.
Code example below is written with .NET 8, Avalonia 11.0.10, with the Avalonia MVVM template with ReactiveUI extensions.
To Reproduce
Easiest just to post the working SSCCE so everyone can recreate. App.axaml/cs and all other files are unchanged from the generated template, only these 2 files are changed:
For MainWindowViewModel.cs
and for MainWindow.axaml
Expected behavior
I would expect the menu items are not disabled and that when clicked, they execute their bound command.
Avalonia version
11.0.10
OS
Windows
Additional context
I note #3100 is the 'same' issue, but that applies to an older Avalonia version and unfortunately that workaround does not work/is not applicable in Avalonia 11. It seems that buggy behaviour was carried over to Avalonia 11 though.
Things I have tried that have no effect, ie the bug still exists:
What "works" is removing the bound command from the axaml, ie removing
Command="{Binding MenuCommand}"
makes the menu item enabled again - but obviously this makes the menu item useless as clicking it does nothing.Binding/command also works when the command is a property of the MainWindowViewModel, though this isn't a solution when the commands are dynamically generated.
The text was updated successfully, but these errors were encountered: