Skip to content

MenuItems from ContextMenu.ItemTemplate disabled / greyed out when Command parameter is used #18032

Closed as not planned
@LazaroOnline

Description

@LazaroOnline

Describe the bug

When a MenuItem Command is binded while in a ContextMenu.ItemTemplate, it seems to be disabled (gray out) and clicking does not work.
Note that all other values bind correctly from the same model, just not the command, and that the command binding is also compiled correctly.

The issue only occurs when ItemsSource with ItemTemplate is used, but if using static MenuItems it does work, example:

<ContextMenu x:DataType="model:User" ItemsSource="{Binding UserLinks}">
  <ContextMenu.ItemTemplate>
	<MenuItem Header="Test" Command="{Binding SomeFUnctionFromUserClass}/>
  </ContextMenu.Item
</ContextMenu>

But of course, static items cannot replace dynamic templates, so it is not a workaround.

To Reproduce

Checkout this simple example in this repo (in the branch issue-example-contextmenu-greyedout):

https://github.com/LazaroOnline/AvaloniaDataGridRowFlyoutRefresh-BugSample/tree/issue-example-contextmenu-greyedout

Run the app and try to right click on the DataGrid row to see the MenuItems that should not be disabled, but they are.

Here is a preview of the axaml from the repo:

<DataGrid.Styles>
  <Style Selector="DataGridRow">
	<Setter Property="ContextMenu">
	  <ContextMenu x:DataType="model:User" ItemsSource="{Binding UserLinks}">
		<ContextMenu.ItemTemplate>
		  <DataTemplate DataType="model:Link">
			<MenuItem Header="{Binding LinkName}" Command="{Binding OpenUrl}" />
		  </DataTemplate>
		</ContextMenu.ItemTemplate>
	  </ContextMenu>
	</Setter>
  </Style>
</DataGrid.Styles>

Expected behavior

No response

Avalonia version

11.2.3

OS

Windows

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugby-designThe behavior reported in the issue is actually correct.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions