From acc6efb3d7d502d0a40020ec86eaff4d018de8be Mon Sep 17 00:00:00 2001 From: Stephane Delcroix Date: Wed, 16 Nov 2016 22:05:28 +0100 Subject: [W] Support 0 as valid BorderWidth (#537) --- Xamarin.Forms.Controls/GalleryPages/ButtonGallery.cs | 1 + Xamarin.Forms.Core.UnitTests/NotifiedPropertiesTests.cs | 2 +- Xamarin.Forms.Core/Button.cs | 2 +- Xamarin.Forms.Platform.WP8/ButtonRenderer.cs | 4 ++-- Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs | 4 ++-- Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Xamarin.Forms.Controls/GalleryPages/ButtonGallery.cs b/Xamarin.Forms.Controls/GalleryPages/ButtonGallery.cs index bb276014..0558b192 100644 --- a/Xamarin.Forms.Controls/GalleryPages/ButtonGallery.cs +++ b/Xamarin.Forms.Controls/GalleryPages/ButtonGallery.cs @@ -101,6 +101,7 @@ namespace Xamarin.Forms.Controls borderButton, new Button {Text = "Thin Border", BorderWidth = 1, BackgroundColor=Color.White, BorderColor = Color.Black, TextColor = Color.Black}, new Button {Text = "Thinner Border", BorderWidth = .5, BackgroundColor=Color.White, BorderColor = Color.Black, TextColor = Color.Black}, + new Button {Text = "BorderWidth == 0", BorderWidth = 0, BackgroundColor=Color.White, BorderColor = Color.Black, TextColor = Color.Black}, timer, busy, alert, diff --git a/Xamarin.Forms.Core.UnitTests/NotifiedPropertiesTests.cs b/Xamarin.Forms.Core.UnitTests/NotifiedPropertiesTests.cs index fcc9d976..1c81c45e 100644 --- a/Xamarin.Forms.Core.UnitTests/NotifiedPropertiesTests.cs +++ b/Xamarin.Forms.Core.UnitTests/NotifiedPropertiesTests.cs @@ -75,7 +75,7 @@ namespace Xamarin.Forms.Core.UnitTests new PropertyTestCase ("Text", v => v.Text, (v, o) => v.Text = o, () => null, "Foo"), new PropertyTestCase ("TextColor", v => v.TextColor, (v, o) => v.TextColor = o, () => Color.Default, new Color (0, 1, 0)), new PropertyTestCase ("Font", v => v.Font, (v, o) => v.Font = o, () => default (Font), Font.SystemFontOfSize (20)), - new PropertyTestCase ("BorderWidth", v => v.BorderWidth, (v, o) => v.BorderWidth = o, () => 0d, 16d), + new PropertyTestCase ("BorderWidth", v => v.BorderWidth, (v, o) => v.BorderWidth = o, () => -1d, 16d), new PropertyTestCase ("BorderRadius", v => v.BorderRadius, (v, o) => v.BorderRadius = o, () => 5, 12), new PropertyTestCase ("BorderColor", v => v.BorderColor, (v, o) => v.BorderColor = o, () => Color.Default, new Color (0, 1, 0)), new PropertyTestCase ("FontFamily", v => v.FontFamily, (v, o) => v.FontFamily = o, () => null, "TestingFace"), diff --git a/Xamarin.Forms.Core/Button.cs b/Xamarin.Forms.Core/Button.cs index 31573076..97d774c9 100644 --- a/Xamarin.Forms.Core/Button.cs +++ b/Xamarin.Forms.Core/Button.cs @@ -33,7 +33,7 @@ namespace Xamarin.Forms public static readonly BindableProperty FontAttributesProperty = BindableProperty.Create("FontAttributes", typeof(FontAttributes), typeof(Button), FontAttributes.None, propertyChanged: SpecificFontPropertyChanged); - public static readonly BindableProperty BorderWidthProperty = BindableProperty.Create("BorderWidth", typeof(double), typeof(Button), 0d); + public static readonly BindableProperty BorderWidthProperty = BindableProperty.Create("BorderWidth", typeof(double), typeof(Button), -1d); public static readonly BindableProperty BorderColorProperty = BindableProperty.Create("BorderColor", typeof(Color), typeof(Button), Color.Default); diff --git a/Xamarin.Forms.Platform.WP8/ButtonRenderer.cs b/Xamarin.Forms.Platform.WP8/ButtonRenderer.cs index 575de4f3..a84a3db6 100644 --- a/Xamarin.Forms.Platform.WP8/ButtonRenderer.cs +++ b/Xamarin.Forms.Platform.WP8/ButtonRenderer.cs @@ -34,7 +34,7 @@ namespace Xamarin.Forms.Platform.WinPhone if (Element.BorderColor != Color.Default) UpdateBorderColor(); - if (Element.BorderWidth != 0) + if (Element.BorderWidth != (double)Button.BorderWidthProperty.DefaultValue) UpdateBorderWidth(); UpdateFont(); @@ -77,7 +77,7 @@ namespace Xamarin.Forms.Platform.WinPhone void UpdateBorderWidth() { - Control.BorderThickness = Element.BorderWidth == 0d ? new WThickness(3) : new WThickness(Element.BorderWidth); + Control.BorderThickness = Element.BorderWidth == (double)Button.BorderWidthProperty.DefaultValue ? new WThickness(3) : new WThickness(Element.BorderWidth); } void UpdateContent() diff --git a/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs b/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs index 018fdd4d..aff11963 100644 --- a/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/ButtonRenderer.cs @@ -45,7 +45,7 @@ namespace Xamarin.Forms.Platform.WinRT if (Element.BorderColor != Color.Default) UpdateBorderColor(); - if (Element.BorderWidth != 0) + if (Element.BorderWidth != (double)Button.BorderWidthProperty.DefaultValue) UpdateBorderWidth(); if (Element.BorderRadius != (int)Button.BorderRadiusProperty.DefaultValue) @@ -121,7 +121,7 @@ namespace Xamarin.Forms.Platform.WinRT void UpdateBorderWidth() { - Control.BorderThickness = Element.BorderWidth == 0d ? new WThickness(3) : new WThickness(Element.BorderWidth); + Control.BorderThickness = Element.BorderWidth == (double)Button.BorderWidthProperty.DefaultValue ? new WThickness(3) : new WThickness(Element.BorderWidth); } void UpdateContent() diff --git a/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs index ac972230..8d043bac 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs @@ -113,7 +113,7 @@ namespace Xamarin.Forms.Platform.iOS if (button.BorderColor != Color.Default) uiButton.Layer.BorderColor = button.BorderColor.ToCGColor(); - uiButton.Layer.BorderWidth = (float)button.BorderWidth; + uiButton.Layer.BorderWidth = Math.Max(0f, (float)button.BorderWidth); uiButton.Layer.CornerRadius = button.BorderRadius; UpdateBackgroundVisibility(); -- cgit v1.2.3