Coder Social home page Coder Social logo

Comments (4)

LeftofZen avatar LeftofZen commented on June 22, 2024 1

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.

rabbitism avatar rabbitism commented on June 22, 2024

The solution in #3100 still works, but your datatemplate content should not be menuitem. Otherwise your will have a menuitem inside menuitem.

from avalonia.

LeftofZen avatar LeftofZen commented on June 22, 2024

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.

image

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.

rabbitism avatar rabbitism commented on June 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.