Skip to content

Commit b867df9

Browse files
FodaMike Corsaro
andauthored
Fix CanvasImageSource scaling behavior (#21239)
Co-authored-by: Mike Corsaro <mikecorsaro@microsoft.com>
1 parent 33b7f79 commit b867df9

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Core/src/Platform/Windows/ButtonExtensions.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#nullable enable
2+
using Microsoft.Graphics.Canvas.UI.Xaml;
23
using Microsoft.Maui.Graphics;
34
using Microsoft.UI.Xaml;
45
using Microsoft.UI.Xaml.Controls;
@@ -159,10 +160,18 @@ public static void UpdateImageSource(this Button platformButton, WImageSource? n
159160
{
160161
if (platformButton.GetContent<WImage>() is WImage nativeImage)
161162
{
162-
// Stretch to the size of the button
163+
// Stretch to fill
163164
nativeImage.Stretch = UI.Xaml.Media.Stretch.Uniform;
164165
nativeImage.Source = nativeImageSource;
165166

167+
// If we're a CanvasImageSource (font image source), we need to explicitly set the image height
168+
// to the desired size of the font, otherwise it will be stretched to the available space
169+
if (nativeImage.Source is CanvasImageSource canvas)
170+
{
171+
nativeImage.Width = canvas.Size.Width;
172+
nativeImage.Height = canvas.Size.Height;
173+
}
174+
166175
nativeImage.Visibility = nativeImageSource == null
167176
? UI.Xaml.Visibility.Collapsed
168177
: UI.Xaml.Visibility.Visible;

0 commit comments

Comments
 (0)