Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/Core/src/Platform/Windows/ButtonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,25 @@ public static void UpdateImageSource(this Button platformButton, WImageSource? n
// to the desired size of the font, otherwise it will be stretched to the available space
if (nativeImage.Source is CanvasImageSource canvas)
{
nativeImage.Width = canvas.Size.Width;
nativeImage.Height = canvas.Size.Height;
var size = canvas.GetImageSourceSize(platformButton);
nativeImage.Width = size.Width;
nativeImage.Height = size.Height;
}

// Ensure that we only scale images down and never up
if (nativeImageSource is BitmapImage bitmapImage)
{
bitmapImage.ImageOpened += OnImageOpened;
void OnImageOpened(object sender, RoutedEventArgs e)
{
bitmapImage.ImageOpened -= OnImageOpened;

var actualImageSource = sender as BitmapImage;
if (actualImageSource is not null)
{
nativeImage.MaxHeight = nativeImageSource.GetImageSourceSize(platformButton).Height;
}
}
}

nativeImage.Visibility = nativeImageSource == null
Expand Down