diff --git a/src/Controls/src/Core/Border/Border.cs b/src/Controls/src/Core/Border/Border.cs
index cc72e2ec5630..2ac3f7ba4380 100644
--- a/src/Controls/src/Core/Border/Border.cs
+++ b/src/Controls/src/Core/Border/Border.cs
@@ -308,13 +308,11 @@ protected override void OnPropertyChanged([CallerMemberName] string? propertyNam
base.OnPropertyChanged(propertyName);
if (propertyName == HeightProperty.PropertyName ||
+ propertyName == StrokeThicknessProperty.PropertyName ||
+ propertyName == StrokeShapeProperty.PropertyName ||
propertyName == WidthProperty.PropertyName)
{
Handler?.UpdateValue(nameof(IBorderStroke.Shape));
- }
- else if (propertyName == StrokeThicknessProperty.PropertyName ||
- propertyName == StrokeShapeProperty.PropertyName)
- {
UpdateStrokeShape();
}
else if (propertyName == StrokeDashArrayProperty.PropertyName)
diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BindingOnStrokeShapeWithRadius.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BindingOnStrokeShapeWithRadius.png
new file mode 100644
index 000000000000..c6bc292532e8
Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BindingOnStrokeShapeWithRadius.png differ
diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BindingOnStrokeShapeWithoutRadius.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BindingOnStrokeShapeWithoutRadius.png
new file mode 100644
index 000000000000..fe0ee61feb27
Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BindingOnStrokeShapeWithoutRadius.png differ
diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22549.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22549.cs
new file mode 100644
index 000000000000..4e0364282f7e
--- /dev/null
+++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22549.cs
@@ -0,0 +1,27 @@
+using NUnit.Framework;
+using UITest.Appium;
+using UITest.Core;
+
+namespace Microsoft.Maui.TestCases.Tests.Issues
+{
+ public class Issue22549 : _IssuesUITest
+ {
+ public Issue22549(TestDevice device) : base(device) { }
+
+ public override string Issue => "Binding Border.StrokeShape not working";
+
+ [Test]
+ public void BindingOnStrokeShapeShouldWork()
+ {
+ App.WaitForElement("button");
+
+ // Border should have radius
+ VerifyScreenshot("BindingOnStrokeShapeWithRadius");
+
+ App.Click("button");
+
+ // The test passes if border radius is equal to 0
+ VerifyScreenshot("BindingOnStrokeShapeWithoutRadius");
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/BindingOnStrokeShapeWithRadius.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/BindingOnStrokeShapeWithRadius.png
new file mode 100644
index 000000000000..0a69049b34f9
Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/BindingOnStrokeShapeWithRadius.png differ
diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/BindingOnStrokeShapeWithoutRadius.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/BindingOnStrokeShapeWithoutRadius.png
new file mode 100644
index 000000000000..2d6b4a246f14
Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/BindingOnStrokeShapeWithoutRadius.png differ
diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/BindingOnStrokeShapeWithRadius.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/BindingOnStrokeShapeWithRadius.png
new file mode 100644
index 000000000000..ec6fd8ca350e
Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/BindingOnStrokeShapeWithRadius.png differ
diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/BindingOnStrokeShapeWithoutRadius.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/BindingOnStrokeShapeWithoutRadius.png
new file mode 100644
index 000000000000..03be00f135d0
Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/BindingOnStrokeShapeWithoutRadius.png differ
diff --git a/src/Controls/tests/TestCases/Issues/Issue22549.xaml b/src/Controls/tests/TestCases/Issues/Issue22549.xaml
new file mode 100644
index 000000000000..bfc2744caf19
--- /dev/null
+++ b/src/Controls/tests/TestCases/Issues/Issue22549.xaml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/Controls/tests/TestCases/Issues/Issue22549.xaml.cs b/src/Controls/tests/TestCases/Issues/Issue22549.xaml.cs
new file mode 100644
index 000000000000..389f110a4b7f
--- /dev/null
+++ b/src/Controls/tests/TestCases/Issues/Issue22549.xaml.cs
@@ -0,0 +1,44 @@
+using Microsoft.Maui;
+using Microsoft.Maui.Controls;
+using Microsoft.Maui.Controls.Shapes;
+using Microsoft.Maui.Controls.Xaml;
+
+namespace Maui.Controls.Sample.Issues;
+
+[XamlCompilation(XamlCompilationOptions.Compile)]
+[Issue(IssueTracker.Github, 22549, "Binding Border.StrokeShape not working", PlatformAffected.All)]
+
+public partial class Issue22549 : ContentPage
+{
+ Issue22549ViewModel _viewModel;
+
+ public Issue22549()
+ {
+ InitializeComponent();
+ BindingContext = _viewModel = new Issue22549ViewModel();
+ }
+
+ void Button_Clicked(System.Object sender, System.EventArgs e)
+ {
+ _viewModel.RoundedRect.CornerRadius = new CornerRadius(0);
+ }
+}
+
+public class Issue22549ViewModel : BindableObject
+{
+ private RoundRectangle _roundedRect;
+ public RoundRectangle RoundedRect
+ {
+ get => _roundedRect;
+ set
+ {
+ _roundedRect = value;
+ OnPropertyChanged();
+ }
+ }
+
+ public Issue22549ViewModel()
+ {
+ RoundedRect = new RoundRectangle() { CornerRadius = new CornerRadius(10) };
+ }
+}
diff --git a/src/Controls/tests/Xaml.UnitTests/Border.xaml b/src/Controls/tests/Xaml.UnitTests/Border.xaml
index 1b2424ed41e5..43c4d8b3f10d 100644
--- a/src/Controls/tests/Xaml.UnitTests/Border.xaml
+++ b/src/Controls/tests/Xaml.UnitTests/Border.xaml
@@ -1,7 +1,8 @@
-
+
+
\ No newline at end of file
diff --git a/src/Controls/tests/Xaml.UnitTests/Border.xaml.cs b/src/Controls/tests/Xaml.UnitTests/Border.xaml.cs
index 7feae77cfdbb..d0ad3389fd8a 100644
--- a/src/Controls/tests/Xaml.UnitTests/Border.xaml.cs
+++ b/src/Controls/tests/Xaml.UnitTests/Border.xaml.cs
@@ -1,4 +1,9 @@
+using System.ComponentModel;
+using System.Runtime.CompilerServices;
using Microsoft.Maui.Controls.Core.UnitTests;
+using Microsoft.Maui.Controls.Shapes;
+using Microsoft.Maui.Dispatching;
+using Microsoft.Maui.UnitTests;
using NUnit.Framework;
namespace Microsoft.Maui.Controls.Xaml.UnitTests
@@ -24,6 +29,46 @@ public void InitializeStrokeShape(bool useCompiledXaml)
Assert.NotNull(layout.Border1.StrokeShape);
Assert.NotNull(layout.Border2.StrokeShape);
}
+
+ [TestCase(false)]
+ [TestCase(true)]
+ public void BindingToStrokeShapeWorks(bool useCompiledXaml)
+ {
+ DispatcherProvider.SetCurrent(new DispatcherProviderStub());
+ var layout = new Border(useCompiledXaml);
+
+ BorderViewModel viewModel = new();
+ layout.BindingContext = viewModel;
+ Assert.IsTrue(layout.BorderWithBinding.StrokeShape is RoundRectangle);
+ Assert.AreEqual(4, ((RoundRectangle)layout.BorderWithBinding.StrokeShape).CornerRadius.TopLeft);
+
+ viewModel.RoundedRect = new RoundRectangle() { CornerRadius = new CornerRadius(8) };
+ Assert.AreEqual(8, ((RoundRectangle)layout.BorderWithBinding.StrokeShape).CornerRadius.TopLeft);
+ DispatcherProvider.SetCurrent(null);
+ }
}
}
+
+ public class BorderViewModel : INotifyPropertyChanged
+ {
+ private RoundRectangle _roundedRect;
+ public RoundRectangle RoundedRect
+ {
+ get => _roundedRect;
+ set
+ {
+ _roundedRect = value;
+ OnPropertyChanged();
+ }
+ }
+
+ public BorderViewModel()
+ {
+ RoundedRect = new RoundRectangle() { CornerRadius = new CornerRadius(4) };
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+ public void OnPropertyChanged([CallerMemberName] string name = "") =>
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
+ }
}
\ No newline at end of file