diff --git a/Perspex.Direct2D1.RenderTests/Controls/BorderTests.cs b/Perspex.Direct2D1.RenderTests/Controls/BorderTests.cs index 907ef6f741..4dbf79fd74 100644 --- a/Perspex.Direct2D1.RenderTests/Controls/BorderTests.cs +++ b/Perspex.Direct2D1.RenderTests/Controls/BorderTests.cs @@ -36,5 +36,42 @@ namespace Perspex.Direct2D1.RenderTests.Controls this.RenderToFile(target); this.CompareImages(); } + + [TestMethod] + public void Border_2px_Border() + { + Decorator target = new Decorator + { + Padding = new Thickness(8), + Width = 200, + Height = 200, + Content = new Border + { + BorderBrush = Brushes.Black, + BorderThickness = 2, + } + }; + + this.RenderToFile(target); + this.CompareImages(); + } + + [TestMethod] + public void Border_Fill() + { + Decorator target = new Decorator + { + Padding = new Thickness(8), + Width = 200, + Height = 200, + Content = new Border + { + Background = Brushes.Red, + } + }; + + this.RenderToFile(target); + this.CompareImages(); + } } } diff --git a/Perspex/Controls/Border.cs b/Perspex/Controls/Border.cs index 197ef18c28..8d6c3415f0 100644 --- a/Perspex/Controls/Border.cs +++ b/Perspex/Controls/Border.cs @@ -27,15 +27,16 @@ namespace Perspex.Controls Brush background = this.Background; Brush borderBrush = this.BorderBrush; double borderThickness = this.BorderThickness; + Rect rect = new Rect(this.Bounds.Size).Deflate(BorderThickness / 2); if (background != null) { - context.FillRectange(background, new Rect(this.Bounds.Size)); + context.FillRectange(background, rect); } if (borderBrush != null && borderThickness > 0) { - context.DrawRectange(new Pen(borderBrush, borderThickness), new Rect(this.Bounds.Size)); + context.DrawRectange(new Pen(borderBrush, borderThickness), rect); } } } diff --git a/Perspex/Media/Brushes.cs b/Perspex/Media/Brushes.cs index 7ecba5d2a4..261fcc98ca 100644 --- a/Perspex/Media/Brushes.cs +++ b/Perspex/Media/Brushes.cs @@ -14,6 +14,7 @@ namespace Perspex.Media static Brushes() { Black = new SolidColorBrush(0xff000000); + Red = new SolidColorBrush(0xffff0000); } public static SolidColorBrush Black @@ -21,5 +22,11 @@ namespace Perspex.Media get; private set; } + + public static SolidColorBrush Red + { + get; + private set; + } } } diff --git a/Perspex/Rect.cs b/Perspex/Rect.cs index 56c99a1f4e..514c69fde7 100644 --- a/Perspex/Rect.cs +++ b/Perspex/Rect.cs @@ -189,6 +189,17 @@ namespace Perspex p.Y >= this.y && p.Y < this.y + this.height; } + /// + /// Deflates the rectangle. + /// + /// The thickness. + /// The deflated rectangle. + /// The deflated rectangle size cannot be less than 0. + public Rect Deflate(double thickness) + { + return this.Deflate(new Thickness(thickness)); + } + /// /// Deflates the rectangle by a . /// diff --git a/TestFiles/Direct2D1/Controls/Border/Border_1px_Border.expected.png b/TestFiles/Direct2D1/Controls/Border/Border_1px_Border.expected.png index ac360079e7..24239d5799 100644 Binary files a/TestFiles/Direct2D1/Controls/Border/Border_1px_Border.expected.png and b/TestFiles/Direct2D1/Controls/Border/Border_1px_Border.expected.png differ diff --git a/TestFiles/Direct2D1/Controls/Border/Border_2px_Border.expected.png b/TestFiles/Direct2D1/Controls/Border/Border_2px_Border.expected.png new file mode 100644 index 0000000000..cebe42f3df Binary files /dev/null and b/TestFiles/Direct2D1/Controls/Border/Border_2px_Border.expected.png differ diff --git a/TestFiles/Direct2D1/Controls/Border/Border_Fill.expected.png b/TestFiles/Direct2D1/Controls/Border/Border_Fill.expected.png new file mode 100644 index 0000000000..8e08d02f66 Binary files /dev/null and b/TestFiles/Direct2D1/Controls/Border/Border_Fill.expected.png differ