diff --git a/src/Controls/src/Core/HandlerImpl/Button/Button.Impl.cs b/src/Controls/src/Core/HandlerImpl/Button/Button.Impl.cs index c5ac6ca268e5..2459e6637fd8 100644 --- a/src/Controls/src/Core/HandlerImpl/Button/Button.Impl.cs +++ b/src/Controls/src/Core/HandlerImpl/Button/Button.Impl.cs @@ -1,4 +1,4 @@ -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; using Microsoft.Maui.Graphics; namespace Microsoft.Maui.Controls @@ -15,6 +15,8 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName Handler?.UpdateValue(nameof(IButtonStroke.StrokeColor)); else if (propertyName == BorderWidthProperty.PropertyName) Handler?.UpdateValue(nameof(IButtonStroke.StrokeThickness)); + else if (propertyName == ImageSourceProperty.PropertyName) + Handler?.UpdateValue(nameof(IImage.Source)); } void IButton.Clicked() diff --git a/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.Android.cs b/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.Android.cs index 203ac2fcae1a..206e1d1a83a1 100644 --- a/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.Android.cs +++ b/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.Android.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading.Tasks; using Android.Text; using AndroidX.AppCompat.Widget; @@ -77,6 +77,31 @@ public async Task CharacterSpacingInitializesCorrectly() Assert.Equal(expectedValue, values.PlatformViewValue, EmCoefficientPrecision); } + [Theory] + [InlineData("red.png", "#FF0000")] + [InlineData("green.png", "#00FF00")] + public async Task ImageSourceUpdatesCorrectly(string filename, string colorHex) + { + var image = new ButtonStub + { + ImageSource = new FileImageSourceStub("black.png"), + }; + + // Update the Button Icon + image.ImageSource = new FileImageSourceStub(filename); + + await InvokeOnMainThreadAsync(async () => + { + var handler = CreateHandler(image); + + bool imageLoaded = await Wait(() => ImageSourceLoaded(handler)); + + Assert.True(imageLoaded); + var expectedColor = Color.FromArgb(colorHex); + await handler.PlatformView.AssertContainsColor(expectedColor); + }); + } + AppCompatButton GetNativeButton(ButtonHandler buttonHandler) => buttonHandler.PlatformView;