Comments (4)
Apologies, this does appear to work. The reason I didn't include Classes
is because Intellisense did not like it and wouldn't autocomplete, and there were also issues with Items -> ItemsSource, but pasting it in does work. Thanks for the help!
from avalonia.
The solution in #3100 still works, but your datatemplate content should not be menuitem. Otherwise your will have a menuitem inside menuitem.
from avalonia.
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:
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MenuItemCommandBug.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="256" d:DesignHeight="128"
x:Class="MenuItemCommandBug.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
Icon="/Assets/avalonia-logo.ico"
Title="MenuItemCommandBug">
<Menu>
<MenuItem Header="Items" ItemsSource="{Binding Items}">
<MenuItem.ItemTemplate>
<DataTemplate>
<MenuItem Header="{Binding Name}" Command="{Binding MenuCommand}" IsEnabled="True" Focusable="True"/>
</DataTemplate>
</MenuItem.ItemTemplate>
<MenuItem.Styles>
<Style Selector="MenuItem.SubItems MenuItem" x:DataType="vm:MenuItemModel">
<Setter Property="Header" Value="{Binding Name}"/>
<Setter Property="Command" Value="{Binding MenuCommand}"/>
</Style>
</MenuItem.Styles>
</MenuItem>
</Menu>
</Window>
On your other point:
but your datatemplate content should not be menuitem. Otherwise your will have a menuitem inside menuitem.
Notice ItemsSource="{Binding Items}"
- this is how you make nested menu items. If you are confused about what this looks like visually, see this screenshot; these sub-menu items are not enabled when they should be.
The last thing you can do to convince yourself this is truly a bug is to remove the Command="{Binding MenuCommand}"
from the axaml. The (sub) menu items are re-enabled again. This shows there is a bug in the interaction of menu items and commands.
from avalonia.
I tried and replied. You didnt set Classes for your Parent MenuItem, thats why it does not work for you.
Classes="SubItems"
from avalonia.
Related Issues (20)
- DataGrid Adaptive exception HOT 6
- AutoCompleteBox not biding SelectedItem when using AsyncPopulator HOT 1
- Screen API refactoring HOT 5
- Android - Crash on bluetooth keyboard device connection and disconnection HOT 2
- [Linux] WindowStartupLocation does not respect DesktopScaling factor HOT 2
- [11.1-beta2] Regression: Window System buttons is not visible when `ExtendClientAreaToDecorationsHint="True"` HOT 2
- AccessViolationException when using RenderDoc on Windows HOT 1
- Copying of file not working as expected
- TabControl item headers go invisible after screen change
- Windows OpenGL FullScreen artifacts with popups and wrong mouse hittests HOT 3
- Double autocompletebox dropdown HOT 3
- Feature Request: Keep a single VkDevice alive per VkInstance so RenderDoc works HOT 1
- Using a string literal for a Label target provokes InvalidCastException when used in a ControlTemplate
- FluentTheme ignores TopLevel.ActualTransparencyLevel HOT 1
- Inconsistent Gesture event names HOT 1
- Consider unsealing the Render() of the Panel? HOT 6
- Alt codes do not produce expected characters
- "Call from invalid thread" process crash after tray icon menu item is invoked HOT 5
- Browser mvvm error HOT 4
- Setting `FontSize` = 0 crashes the previewer in VS 2022
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from avalonia.