From 6e6477d40682d068048517588aba7693866a6709 Mon Sep 17 00:00:00 2001 From: Paillat Laszlo Date: Tue, 17 Jun 2025 18:28:47 +0200 Subject: [PATCH] changed MenuItem Icon to properly set :icon pseudo class as long as value is not null (#19075) --- src/Avalonia.Controls/MenuItem.cs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Avalonia.Controls/MenuItem.cs b/src/Avalonia.Controls/MenuItem.cs index 1a4b4974b2..f250f8da43 100644 --- a/src/Avalonia.Controls/MenuItem.cs +++ b/src/Avalonia.Controls/MenuItem.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Collections.Specialized; using System.Linq; using System.Windows.Input; using Avalonia.Automation; @@ -571,7 +570,7 @@ namespace Avalonia.Controls } } } - + /// /// Closes all submenus of the menu item. /// @@ -609,12 +608,12 @@ namespace Avalonia.Controls } } - + private static void OnAccessKeyPressed(MenuItem sender, AccessKeyPressedEventArgs e) { - if (e is not { Handled: false, Target: null }) + if (e is not { Handled: false, Target: null }) return; - + e.Target = sender; e.Handled = true; } @@ -789,15 +788,23 @@ namespace Avalonia.Controls { var (oldValue, newValue) = e.GetOldAndNewValue(); - if (oldValue is ILogical oldLogical) + if (oldValue is { }) { - LogicalChildren.Remove(oldLogical); + if (oldValue is ILogical oldLogical) + { + LogicalChildren.Remove(oldLogical); + } + PseudoClasses.Remove(":icon"); } - if (newValue is ILogical newLogical) + if (newValue is { }) { - LogicalChildren.Add(newLogical); + if (newValue is ILogical newLogical) + { + LogicalChildren.Add(newLogical); + } + PseudoClasses.Add(":icon"); } }