From 34ba4c9c823188b01713c69d34fe43fae9af768a Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 15 Jun 2023 12:00:50 +0200 Subject: [PATCH] Actually invalidate menuitems when it got attached to the visual tree --- src/Avalonia.Controls/MenuItem.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Avalonia.Controls/MenuItem.cs b/src/Avalonia.Controls/MenuItem.cs index 1bb53f90a8..08c36122ea 100644 --- a/src/Avalonia.Controls/MenuItem.cs +++ b/src/Avalonia.Controls/MenuItem.cs @@ -394,6 +394,13 @@ namespace Avalonia.Controls _isEmbeddedInMenu = parent?.FindLogicalAncestorOfType(true) != null; } + protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) + { + base.OnAttachedToVisualTree(e); + + TryUpdateCanExecute(); + } + protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e) { // This will cause the hotkey manager to dispose the observer and the reference to this control