From e4da06aaafec45439715d3e7e4c8953bcf405200 Mon Sep 17 00:00:00 2001 From: ema Date: Thu, 29 Aug 2024 19:03:56 +0800 Subject: [PATCH 1/2] feat: support ClipToBounds for Border --- .../EleCho.WpfSuite.FluentDesign.csproj | 4 ---- EleCho.WpfSuite/Controls/Border.cs | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/EleCho.WpfSuite.FluentDesign/EleCho.WpfSuite.FluentDesign.csproj b/EleCho.WpfSuite.FluentDesign/EleCho.WpfSuite.FluentDesign.csproj index 7b039d2..3521cc7 100644 --- a/EleCho.WpfSuite.FluentDesign/EleCho.WpfSuite.FluentDesign.csproj +++ b/EleCho.WpfSuite.FluentDesign/EleCho.WpfSuite.FluentDesign.csproj @@ -24,10 +24,6 @@ - - - - Designer diff --git a/EleCho.WpfSuite/Controls/Border.cs b/EleCho.WpfSuite/Controls/Border.cs index 18a3333..e65f456 100644 --- a/EleCho.WpfSuite/Controls/Border.cs +++ b/EleCho.WpfSuite/Controls/Border.cs @@ -266,5 +266,19 @@ internal Radii(CornerRadius radii, Thickness borders, bool outer) internal double BottomLeft; internal double LeftBottom; } + + /// + protected override Geometry GetLayoutClip(Size layoutSlotSize) + { + if (ClipToBounds) + { + var radius = CornerRadius.TopLeft; + var rect = new RectangleGeometry(new Rect(layoutSlotSize), radius, radius); + rect.Freeze(); + return rect; + } + + return base.GetLayoutClip(layoutSlotSize); + } } } From 8fcdcfe5af27a4e2414b921f84ff1e1dbfee8545 Mon Sep 17 00:00:00 2001 From: ilyfairy Date: Thu, 29 Aug 2024 20:44:19 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E6=AD=A3=E7=A1=AE=E5=9C=B0=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=20LayoutClip=20=E8=A3=81=E5=89=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EleCho.WpfSuite/Controls/Border.cs | 53 ++++++++++++++++++------------ WpfTest/Tests/TempPage.xaml | 9 ++++- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/EleCho.WpfSuite/Controls/Border.cs b/EleCho.WpfSuite/Controls/Border.cs index e65f456..e28cd0e 100644 --- a/EleCho.WpfSuite/Controls/Border.cs +++ b/EleCho.WpfSuite/Controls/Border.cs @@ -53,7 +53,6 @@ public Geometry ContentClip contentGeometry.Freeze(); return contentGeometry; - } else { @@ -62,10 +61,36 @@ public Geometry ContentClip } /// - protected override void OnRender(DrawingContext dc) + protected override Size ArrangeOverride(Size finalSize) { SetValue(ContentClipPropertyKey, CalculateContentClip()); - base.OnRender(dc); + + return base.ArrangeOverride(finalSize); + } + + /// + protected override Geometry GetLayoutClip(Size layoutSlotSize) + { + var borderThickness = BorderThickness; + var cornerRadius = CornerRadius; + var renderSize = RenderSize; + + if (renderSize.Width > 0 && renderSize.Height > 0) + { + var rect = new Rect(0, 0, renderSize.Width, renderSize.Height); + var radii = new Radii(cornerRadius, borderThickness, true); + + var layoutGeometry = new StreamGeometry(); + using StreamGeometryContext ctx = layoutGeometry.Open(); + GenerateGeometry(ctx, rect, radii); + + layoutGeometry.Freeze(); + return layoutGeometry; + } + else + { + return base.GetLayoutClip(layoutSlotSize); + } } /// @@ -200,10 +225,10 @@ private struct Radii { internal Radii(CornerRadius radii, Thickness borders, bool outer) { - double left = 0.5 * borders.Left; - double top = 0.5 * borders.Top; - double right = 0.5 * borders.Right; - double bottom = 0.5 * borders.Bottom; + double left = 0.5 * borders.Left; + double top = 0.5 * borders.Top; + double right = 0.5 * borders.Right; + double bottom = 0.5 * borders.Bottom; if (outer) { @@ -266,19 +291,5 @@ internal Radii(CornerRadius radii, Thickness borders, bool outer) internal double BottomLeft; internal double LeftBottom; } - - /// - protected override Geometry GetLayoutClip(Size layoutSlotSize) - { - if (ClipToBounds) - { - var radius = CornerRadius.TopLeft; - var rect = new RectangleGeometry(new Rect(layoutSlotSize), radius, radius); - rect.Freeze(); - return rect; - } - - return base.GetLayoutClip(layoutSlotSize); - } } } diff --git a/WpfTest/Tests/TempPage.xaml b/WpfTest/Tests/TempPage.xaml index a7d43b7..28eb8b0 100644 --- a/WpfTest/Tests/TempPage.xaml +++ b/WpfTest/Tests/TempPage.xaml @@ -251,7 +251,14 @@ - + + +