diff --git a/src/Avalonia.Controls/Border.cs b/src/Avalonia.Controls/Border.cs
index 93a6c203c9..8acb3603c9 100644
--- a/src/Avalonia.Controls/Border.cs
+++ b/src/Avalonia.Controls/Border.cs
@@ -43,7 +43,8 @@ namespace Avalonia.Controls
///
static Border()
{
- AffectsRender(BackgroundProperty, BorderBrushProperty);
+ AffectsRender(BackgroundProperty, BorderBrushProperty, BorderThicknessProperty, CornerRadiusProperty);
+ AffectsMeasure(BorderThicknessProperty);
}
///
diff --git a/src/Avalonia.Controls/Presenters/ContentPresenter.cs b/src/Avalonia.Controls/Presenters/ContentPresenter.cs
index ce8fe52c22..3cc750e20d 100644
--- a/src/Avalonia.Controls/Presenters/ContentPresenter.cs
+++ b/src/Avalonia.Controls/Presenters/ContentPresenter.cs
@@ -89,6 +89,8 @@ namespace Avalonia.Controls.Presenters
///
static ContentPresenter()
{
+ AffectsRender(BackgroundProperty, BorderBrushProperty, BorderThicknessProperty, CornerRadiusProperty);
+ AffectsMeasure(BorderThicknessProperty);
ContentProperty.Changed.AddClassHandler(x => x.ContentChanged);
ContentTemplateProperty.Changed.AddClassHandler(x => x.ContentChanged);
TemplatedParentProperty.Changed.AddClassHandler(x => x.TemplatedParentChanged);
diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs
index 6005ee8b8f..799380cb85 100644
--- a/src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs
+++ b/src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs
@@ -167,7 +167,9 @@ namespace Avalonia.Rendering.SceneGraph
using (context.PushPostTransform(m))
using (context.PushTransformContainer())
{
- var clipBounds = bounds.TransformToAABB(contextImpl.Transform).Intersect(clip);
+ var clipBounds = clipToBounds ?
+ bounds.TransformToAABB(contextImpl.Transform).Intersect(clip) :
+ clip;
forceRecurse = forceRecurse ||
node.ClipBounds != clipBounds ||
diff --git a/tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs b/tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs
index 2ada7bdbba..df4584518e 100644
--- a/tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs
+++ b/tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs
@@ -83,6 +83,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
Margin = new Thickness(10, 20, 30, 40),
Child = canvas = new Canvas
{
+ ClipToBounds = true,
Background = Brushes.AliceBlue,
}
}
@@ -129,6 +130,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
(border = new Border
{
Background = Brushes.AliceBlue,
+ ClipToBounds = true,
Width = 100,
Height = 100,
[Canvas.LeftProperty] = 50,
@@ -173,6 +175,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
(border = new Border
{
Background = Brushes.AliceBlue,
+ ClipToBounds = true,
Width = 100,
Height = 100,
[Canvas.LeftProperty] = 50,
@@ -254,6 +257,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
Margin = new Thickness(24, 26),
Child = target = new Border
{
+ ClipToBounds = true,
Margin = new Thickness(26, 24),
Width = 100,
Height = 100,
@@ -515,6 +519,50 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
}
}
+ [Fact]
+ public void Should_Update_ClipBounds_For_Negative_Margin()
+ {
+ using (TestApplication())
+ {
+ Decorator decorator;
+ Border border;
+ var tree = new TestRoot
+ {
+ Width = 100,
+ Height = 100,
+ Child = decorator = new Decorator
+ {
+ Margin = new Thickness(0, 10, 0, 0),
+ Child = border = new Border
+ {
+ Background = Brushes.Red,
+ ClipToBounds = true,
+ Margin = new Thickness(0, -5, 0, 0),
+ }
+ }
+ };
+
+ var layout = AvaloniaLocator.Current.GetService();
+ layout.ExecuteInitialLayoutPass(tree);
+
+ var scene = new Scene(tree);
+ var sceneBuilder = new SceneBuilder();
+ sceneBuilder.UpdateAll(scene);
+
+ var borderNode = scene.FindNode(border);
+ Assert.Equal(new Rect(0, 5, 100, 95), borderNode.ClipBounds);
+
+ border.Margin = new Thickness(0, -8, 0, 0);
+ layout.ExecuteLayoutPass();
+
+ scene = scene.CloneScene();
+ sceneBuilder.Update(scene, border);
+
+ borderNode = scene.FindNode(border);
+ Assert.Equal(new Rect(0, 2, 100, 98), borderNode.ClipBounds);
+ }
+ }
+
[Fact]
public void Should_Update_Descendent_Tranform_When_Margin_Changed()
{