diff --git a/tests/Avalonia.Controls.UnitTests/MenuItemTests.cs b/tests/Avalonia.Controls.UnitTests/MenuItemTests.cs index 7f7b69056c..59cfc67f24 100644 --- a/tests/Avalonia.Controls.UnitTests/MenuItemTests.cs +++ b/tests/Avalonia.Controls.UnitTests/MenuItemTests.cs @@ -62,6 +62,58 @@ namespace Avalonia.Controls.UnitTests Assert.False(target.IsEffectivelyEnabled); } + [Fact] + public void MenuItem_With_Styled_Command_Binding_Should_Be_Enabled_With_Child_Missing_Command() + { + var childViewModel = new TestMenuElement("Child"); + var parentViewModel = new TestMenuElement("Parent", new[] { childViewModel }); + + var contextMenu = new ContextMenu + { + ItemsSource = new[] { parentViewModel }, + Styles = + { + new Style(x => x.OfType()) + { + Setters = + { + new Setter(MenuItem.HeaderProperty, new Binding("Header")), + new Setter(MenuItem.ItemsSourceProperty, new Binding("Elements")), + new Setter(MenuItem.CommandProperty, new Binding("Command")) + } + } + } + }; + + using (Application()) + { + var window = new Window { Content = new Panel { ContextMenu = contextMenu } }; + window.ApplyStyling(); + window.ApplyTemplate(); + window.Presenter.ApplyTemplate(); + + contextMenu.Open(); + + var parentMenuItem = contextMenu.Presenter.Panel.Children[0] as MenuItem; + + Assert.NotNull(parentMenuItem); + Assert.True(parentMenuItem.IsEnabled); + Assert.True(parentMenuItem.IsEffectivelyEnabled); + } + } + + public class TestMenuElement + { + public string Header { get; } + public IList Elements { get; } + + public TestMenuElement(string header, IList elements = null) + { + Header = header; + Elements = elements ?? new List(); + } + } + [Fact] public void MenuItem_Is_Disabled_When_Bound_Command_Is_Removed() {