Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding Border.StrokeShape stopped working - fix #22558

Merged
merged 6 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 2 additions & 4 deletions src/Controls/src/Core/Border/Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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();

App.Click("button");

//The test passes if border radius is equal to 0
VerifyScreenshot();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These may need to have a custom filename since they are different.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, added different names.

}
}
}
19 changes: 19 additions & 0 deletions src/Controls/tests/TestCases/Issues/Issue22549.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue22549"
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"
Title="Issue22549">
<VerticalStackLayout Padding="30,0" Spacing="25">
<Border x:Name="myBorder"
Margin="0,10,0,0"
BackgroundColor="Blue"
StrokeShape="{Binding Source={RelativeSource AncestorType={x:Type local:Issue22549ViewModel}}, Path=RoundedRect}">
<Label Text="Welcome to &#10;.NET Multi-platform App UI"
TextColor="White" />
</Border>
<Button AutomationId="button"
Text="Click me"
Clicked="Button_Clicked" />
</VerticalStackLayout>
</ContentPage>
44 changes: 44 additions & 0 deletions src/Controls/tests/TestCases/Issues/Issue22549.xaml.cs
Original file line number Diff line number Diff line change
@@ -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) };
}
}
7 changes: 5 additions & 2 deletions src/Controls/tests/Xaml.UnitTests/Border.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Microsoft.Maui.Controls.Xaml.UnitTests"
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Border">
<StackLayout>
<Border
Expand All @@ -22,5 +23,7 @@
<Label
Text="Ellipse"/>
</Border>
<Border x:Name="BorderWithBinding"
StrokeShape="{Binding Source={RelativeSource AncestorType={x:Type local:BorderViewModel}}, Path=RoundedRect}"/>
</StackLayout>
</ContentPage>
45 changes: 45 additions & 0 deletions src/Controls/tests/Xaml.UnitTests/Border.xaml.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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));
}
}
Loading