From b72224ea0b01e56d56e85c39b5f409fcc74a9fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Pol=C3=A1=C5=A1ek?= Date: Mon, 9 Mar 2026 12:15:23 +0100 Subject: [PATCH] CmdPal: Ensure IconBox uses an initialized scale (#45980) ## Summary of the Pull Request This PR makes sure that IconBox is using valid scale to prevent defaulting to 0 and using poorly resizes full-scale image: image vs image ## PR Checklist - [x] Closes: #45973 --- .../Microsoft.CmdPal.UI/Controls/IconBox.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/IconBox.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/IconBox.cs index 2fad25cec3..4629dd6464 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/IconBox.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/IconBox.cs @@ -135,6 +135,8 @@ public partial class IconBox : ContentControl _lastScale = XamlRoot.RasterizationScale; XamlRoot.Changed += OnXamlRootChanged; } + + Refresh(); } private void OnUnloaded(object sender, RoutedEventArgs e) @@ -149,10 +151,13 @@ public partial class IconBox : ContentControl { var newScale = sender.RasterizationScale; var changedLastTheme = _lastTheme != ActualTheme; + var changedScale = Math.Abs(newScale - _lastScale) > 0.01; + + _lastScale = newScale; _lastTheme = ActualTheme; - if ((changedLastTheme || Math.Abs(newScale - _lastScale) > 0.01) && SourceKey is not null) + + if ((changedLastTheme || changedScale) && SourceKey is not null) { - _lastScale = newScale; UpdateSourceKey(this, SourceKey); } } @@ -257,7 +262,11 @@ public partial class IconBox : ContentControl return; } - var eventArgs = new SourceRequestedEventArgs(sourceKey, iconBox._lastTheme, iconBox._lastScale); + var scale = iconBox._lastScale > 0 + ? iconBox._lastScale + : (iconBox.XamlRoot?.RasterizationScale > 0 ? iconBox.XamlRoot.RasterizationScale : 1.0); + + var eventArgs = new SourceRequestedEventArgs(sourceKey, iconBox._lastTheme, scale); await iconBoxSourceRequestedHandler.InvokeAsync(iconBox, eventArgs); // After the await: