Browse Source

Added failing test.

pull/8263/head
Steven Kirk 4 years ago
parent
commit
5fd854e35b
  1. 36
      tests/Avalonia.Base.UnitTests/Styling/StyledElementTests_Theming.cs

36
tests/Avalonia.Base.UnitTests/Styling/StyledElementTests_Theming.cs

@ -189,6 +189,36 @@ public class StyledElementTests_Theming
Assert.Null(((IStyleable)target).GetEffectiveTheme());
}
[Fact]
public void Nested_Style_Can_Override_Property_In_Inner_Templated_Control()
{
using var app = UnitTestApplication.Start(TestServices.RealStyler);
var target = new ThemedControl2
{
Theme = new ControlTheme(typeof(ThemedControl2))
{
Setters =
{
new Setter(
TemplatedControl.TemplateProperty,
new FuncControlTemplate<ThemedControl2>((o, n) => new ThemedControl())),
},
Children =
{
new Style(x => x.Nesting().Template().OfType<ThemedControl>())
{
Setters = { new Setter(TemplatedControl.CornerRadiusProperty, new CornerRadius(7)), }
},
}
},
};
var root = CreateRoot(target);
var inner = Assert.IsType<ThemedControl>(target.VisualChild);
Assert.Equal(new CornerRadius(7), inner.CornerRadius);
}
private static ThemedControl CreateTarget() => new ThemedControl();
private static TestRoot CreateRoot(IControl child)
@ -332,6 +362,7 @@ public class StyledElementTests_Theming
Setters =
{
new Setter(TemplatedControl.TemplateProperty, template),
new Setter(TemplatedControl.CornerRadiusProperty, new CornerRadius(5)),
},
Children =
{
@ -376,6 +407,11 @@ public class StyledElementTests_Theming
public IVisual? VisualChild => VisualChildren?.SingleOrDefault();
}
private class ThemedControl2 : TemplatedControl
{
public IVisual? VisualChild => VisualChildren?.SingleOrDefault();
}
private class DerivedThemedControl : ThemedControl
{
}

Loading…
Cancel
Save