Ver código fonte

working enabled when using click handlers.

Dan Walmsley 6 anos atrás
pai
commit
aaedaebe94

+ 0 - 1
src/Avalonia.Controls/NativeMenu.cs

@@ -48,7 +48,6 @@ namespace Avalonia.Controls
             set => SetAndRaise(ParentProperty, ref _parent, value);
         }
 
-        
         public void Add(NativeMenuItem item) => _items.Add(item);
         
         public IEnumerator<NativeMenuItem> GetEnumerator() => _items.GetEnumerator();

+ 2 - 0
src/Avalonia.Controls/NativeMenuItem.cs

@@ -110,6 +110,8 @@ namespace Avalonia.Controls
             Enabled = _command?.CanExecute(null) ?? true;
         }
 
+        public bool HasClickHandlers => Clicked != null;
+
         public ICommand Command
         {
             get => GetValue(CommandProperty);

+ 8 - 5
src/Avalonia.Native/AvaloniaNativeMenuExporter.cs

@@ -48,13 +48,14 @@ namespace Avalonia.Native
         private Dictionary<int, NativeMenuItem> _idsToItems = new Dictionary<int, NativeMenuItem>();
         private Dictionary<NativeMenuItem, int> _itemsToIds = new Dictionary<NativeMenuItem, int>();
         private uint _revision = 1;
+        private bool _exported = false;
 
         public AvaloniaNativeMenuExporter(IAvaloniaNativeFactory factory)
         {
             _factory = factory;
         }
 
-        public bool IsNativeMenuExported => throw new NotImplementedException();
+        public bool IsNativeMenuExported => _exported;
 
         public event EventHandler OnIsNativeMenuExportedChanged;
 
@@ -113,6 +114,8 @@ namespace Avalonia.Native
             LayoutUpdated?.Invoke((_revision, 0));
 
             SetMenu(_menu.Items);
+
+            _exported = true;
         }
 
         private void QueueReset()
@@ -153,9 +156,9 @@ namespace Avalonia.Native
 
                 menuItem.SetAction(new PredicateCallback(() =>
                 {
-                    if (item.Command != null)
+                    if (item.Command != null || item.HasClickHandlers)
                     {
-                        return item.Command.CanExecute(null);
+                        return item.Enabled;
                     }
 
                     return false;
@@ -186,9 +189,9 @@ namespace Avalonia.Native
 
                 menuItem.SetAction(new PredicateCallback(() =>
                 {
-                    if (item.Command != null)
+                    if (item.Command != null || item.HasClickHandlers)
                     {
-                        return item.Command.CanExecute(null);
+                        return item.Enabled;
                     }
 
                     return false;