mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 09:46:54 +02:00
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: <img width="81" height="79" alt="image" src="https://github.com/user-attachments/assets/55bbb08f-6f78-4c19-b7a6-748176dee9c8" /> vs <img width="89" height="88" alt="image" src="https://github.com/user-attachments/assets/2dc26863-88c0-4c47-8798-023611d571b5" /> <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] Closes: #45973
This commit is contained in:
@@ -135,6 +135,8 @@ public partial class IconBox : ContentControl
|
|||||||
_lastScale = XamlRoot.RasterizationScale;
|
_lastScale = XamlRoot.RasterizationScale;
|
||||||
XamlRoot.Changed += OnXamlRootChanged;
|
XamlRoot.Changed += OnXamlRootChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnUnloaded(object sender, RoutedEventArgs e)
|
private void OnUnloaded(object sender, RoutedEventArgs e)
|
||||||
@@ -149,10 +151,13 @@ public partial class IconBox : ContentControl
|
|||||||
{
|
{
|
||||||
var newScale = sender.RasterizationScale;
|
var newScale = sender.RasterizationScale;
|
||||||
var changedLastTheme = _lastTheme != ActualTheme;
|
var changedLastTheme = _lastTheme != ActualTheme;
|
||||||
|
var changedScale = Math.Abs(newScale - _lastScale) > 0.01;
|
||||||
|
|
||||||
|
_lastScale = newScale;
|
||||||
_lastTheme = ActualTheme;
|
_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);
|
UpdateSourceKey(this, SourceKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -257,7 +262,11 @@ public partial class IconBox : ContentControl
|
|||||||
return;
|
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);
|
await iconBoxSourceRequestedHandler.InvokeAsync(iconBox, eventArgs);
|
||||||
|
|
||||||
// After the await:
|
// After the await:
|
||||||
|
|||||||
Reference in New Issue
Block a user