From 104733b4d0f076749c23729e6c4cfc57c06561ce Mon Sep 17 00:00:00 2001 From: TJ Lambert <50846373+tj-devel709@users.noreply.github.com> Date: Thu, 13 Oct 2022 10:36:10 -0500 Subject: [PATCH 1/4] Revert "Fix default corner radius on Windows Button (#9515) Fixes #7128" This reverts commit ed53643a91933cb96fe2240a7300859288bf186d. --- src/Core/src/Platform/Windows/ButtonExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Core/src/Platform/Windows/ButtonExtensions.cs b/src/Core/src/Platform/Windows/ButtonExtensions.cs index 00683465558d..5b856a4f9c9f 100644 --- a/src/Core/src/Platform/Windows/ButtonExtensions.cs +++ b/src/Core/src/Platform/Windows/ButtonExtensions.cs @@ -50,10 +50,10 @@ public static void UpdateStrokeThickness(this Button platformButton, IButtonStro public static void UpdateCornerRadius(this Button platformButton, IButtonStroke buttonStroke) { - var radius = buttonStroke.CornerRadius > -1 ? buttonStroke.CornerRadius : 0; + var radius = buttonStroke.CornerRadius; if (radius >= 0) - platformButton.Resources.SetValueForAllKey(CornerRadiusResourceKeys, WinUIHelpers.CreateCornerRadius(radius)); + platformButton.Resources.SetValueForAllKey(CornerRadiusResourceKeys, WinUIHelpers.CreateCornerRadius(buttonStroke.CornerRadius)); else platformButton.Resources.RemoveKeys(CornerRadiusResourceKeys); From 7304a33f9d5628c015fd02b2ceda3c2940ec747a Mon Sep 17 00:00:00 2001 From: tj-devel709 Date: Thu, 13 Oct 2022 22:32:25 -0500 Subject: [PATCH 2/4] add test --- src/Core/src/Platform/Windows/ButtonExtensions.cs | 2 +- .../Handlers/Window/WindowHandlerTests.Windows.cs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Core/src/Platform/Windows/ButtonExtensions.cs b/src/Core/src/Platform/Windows/ButtonExtensions.cs index 5b856a4f9c9f..6be5bf82fac8 100644 --- a/src/Core/src/Platform/Windows/ButtonExtensions.cs +++ b/src/Core/src/Platform/Windows/ButtonExtensions.cs @@ -53,7 +53,7 @@ public static void UpdateCornerRadius(this Button platformButton, IButtonStroke var radius = buttonStroke.CornerRadius; if (radius >= 0) - platformButton.Resources.SetValueForAllKey(CornerRadiusResourceKeys, WinUIHelpers.CreateCornerRadius(buttonStroke.CornerRadius)); + platformButton.Resources.SetValueForAllKey(CornerRadiusResourceKeys, WinUIHelpers.CreateCornerRadius(radius)); else platformButton.Resources.RemoveKeys(CornerRadiusResourceKeys); diff --git a/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.Windows.cs b/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.Windows.cs index e269d74e1695..20d1f340f822 100644 --- a/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.Windows.cs +++ b/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.Windows.cs @@ -161,6 +161,13 @@ await RunWindowTest(window, handler => }); } + [Fact(DisplayName = "Rounded Maui Buttons Default Style")] + public void RoundedCornersMauiButtons() + { + var button = new Microsoft.Maui.Controls.Button(); + Assert.True(button.CornerRadius != 0); + } + void MovePlatformWindow(UI.Xaml.Window window, Rect rect) { var density = window.GetDisplayDensity(); From 81af3770b03193c3a40f44d403935cc229da8b5d Mon Sep 17 00:00:00 2001 From: tj-devel709 Date: Thu, 13 Oct 2022 22:39:18 -0500 Subject: [PATCH 3/4] remove unneeded class reference --- .../DeviceTests/Handlers/Window/WindowHandlerTests.Windows.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.Windows.cs b/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.Windows.cs index 20d1f340f822..62e6f8b73203 100644 --- a/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.Windows.cs +++ b/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.Windows.cs @@ -164,7 +164,7 @@ await RunWindowTest(window, handler => [Fact(DisplayName = "Rounded Maui Buttons Default Style")] public void RoundedCornersMauiButtons() { - var button = new Microsoft.Maui.Controls.Button(); + var button = new Button(); Assert.True(button.CornerRadius != 0); } From 0700f6c47bef8eb25e6b02146a1c3f9b3b0f0762 Mon Sep 17 00:00:00 2001 From: tj-devel709 Date: Fri, 14 Oct 2022 16:26:45 -0500 Subject: [PATCH 4/4] Move the test and check the native button --- .../Button/ButtonHandlerTests.Windows.cs | 25 +++++++++++++++++++ .../Window/WindowHandlerTests.Windows.cs | 7 ------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.Windows.cs b/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.Windows.cs index 526914da37c5..3cfce781e92a 100644 --- a/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.Windows.cs +++ b/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.Windows.cs @@ -38,6 +38,31 @@ public async Task CharacterSpacingInitializesCorrectly() Assert.Equal(expectedValue, values.PlatformViewValue); } + [Fact(DisplayName = "Rounded Maui Buttons Default Style")] + public async Task RoundedCornersMauiButtons() + { + var flatCornerRadius = 0; + var b = new Maui.Controls.Button(); + + var button = new ButtonStub() + { + // assign ButtonStub the default CornerRadius value of a Maui.Controls.Button + CornerRadius = b.CornerRadius + }; + + var values = await GetValueAsync(button, (handler) => + { + return new + { + ViewValue = button.CornerRadius, + platformResources = handler.PlatformView.Resources + }; + }); + + Assert.False(values.platformResources.ContainsKey("ControlCornerRadius")); + Assert.NotEqual(flatCornerRadius, values.ViewValue); + } + UI.Xaml.Controls.Button GetNativeButton(ButtonHandler buttonHandler) => buttonHandler.PlatformView; diff --git a/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.Windows.cs b/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.Windows.cs index 62e6f8b73203..e269d74e1695 100644 --- a/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.Windows.cs +++ b/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.Windows.cs @@ -161,13 +161,6 @@ await RunWindowTest(window, handler => }); } - [Fact(DisplayName = "Rounded Maui Buttons Default Style")] - public void RoundedCornersMauiButtons() - { - var button = new Button(); - Assert.True(button.CornerRadius != 0); - } - void MovePlatformWindow(UI.Xaml.Window window, Rect rect) { var density = window.GetDisplayDensity();