Skip to content

Commit

Permalink
Replaced BackgroundColor into default template binding for border, cr…
Browse files Browse the repository at this point in the history
…eated new test for BorderColorProperty, BorderWidthProperty, and CornerRadiusProperty
  • Loading branch information
dustin-wojciechowski committed Feb 28, 2023
1 parent 51d81ee commit 372d949
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Controls/src/Core/RadioButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ static View BuildDefaultTemplate()
Padding = 6
};

BindToTemplatedParent(border, BackgroundProperty, HorizontalOptionsProperty,
BindToTemplatedParent(border, BackgroundColorProperty, HorizontalOptionsProperty,
MarginProperty, OpacityProperty, RotationProperty, ScaleProperty, ScaleXProperty, ScaleYProperty,
TranslationYProperty, TranslationXProperty, VerticalOptionsProperty);

Expand Down
26 changes: 23 additions & 3 deletions src/Controls/tests/Core.UnitTests/RadioButtonTemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ public IEnumerator<object[]> GetEnumerator()
yield return new object[] { RadioButton.VerticalOptionsProperty, LayoutOptions.End };
yield return new object[] { RadioButton.HorizontalOptionsProperty, LayoutOptions.End };
yield return new object[] { RadioButton.BackgroundColorProperty, Colors.Red };
yield return new object[] { RadioButton.BorderColorProperty, Colors.Magenta };
yield return new object[] { RadioButton.BorderWidthProperty, 4 };
yield return new object[] { RadioButton.CornerRadiusProperty, 4 };
yield return new object[] { RadioButton.MarginProperty, new Thickness(1, 2, 3, 4) };
yield return new object[] { RadioButton.OpacityProperty, 0.67 };
yield return new object[] { RadioButton.RotationProperty, 0.3 };
Expand Down Expand Up @@ -95,5 +92,28 @@ public void RadioButtonStyleSetsPropertyOnTemplateRoot(BindableProperty property
Assert.NotNull(root);
Assert.Equal(root.GetValue(property), value);
}

[Fact]
public void BorderSpecificRadioButtonStyleSetsPropertyOnTemplateRoot()
{
var borderColor = Colors.Magenta;
var borderWidthProperty = 4.3;
var cornerRadiusProperty = 5;
var radioButtonStyle = new Style(typeof(RadioButton));

radioButtonStyle.Setters.Add(new Setter() { Property = RadioButton.BorderColorProperty, Value = borderColor });
radioButtonStyle.Setters.Add(new Setter() { Property = RadioButton.BorderWidthProperty, Value = borderWidthProperty });
radioButtonStyle.Setters.Add(new Setter() { Property = RadioButton.CornerRadiusProperty, Value = cornerRadiusProperty });

var radioButton = new RadioButton() { ControlTemplate = RadioButton.DefaultTemplate, Style = radioButtonStyle };
var root = (radioButton as IControlTemplated)?.TemplateRoot as Border;

Assert.NotNull(root);
Assert.Equal(root.GetValue(Border.StrokeProperty), Brush.Magenta);
Assert.Equal(root.GetValue(Border.StrokeThicknessProperty), borderWidthProperty);

RoundRectangle rec = (RoundRectangle)root.StrokeShape;
Assert.Equal(rec.CornerRadius, cornerRadiusProperty);
}
}
}

0 comments on commit 372d949

Please sign in to comment.