From 1212e2444769f76c60c75b8b06e4988fcdae7ff3 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sun, 24 Nov 2019 15:45:31 +0800 Subject: [PATCH 1/4] Hackfix for #3284 --- src/Avalonia.Controls/Primitives/RangeBase.cs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Avalonia.Controls/Primitives/RangeBase.cs b/src/Avalonia.Controls/Primitives/RangeBase.cs index f1ee7c0e1a..39d00b6953 100644 --- a/src/Avalonia.Controls/Primitives/RangeBase.cs +++ b/src/Avalonia.Controls/Primitives/RangeBase.cs @@ -75,8 +75,11 @@ namespace Avalonia.Controls.Primitives set { - ValidateDouble(value, "Minimum"); - + if (!ValidateDouble(value)) + { + value = _minimum; + } + if (IsInitialized) { SetAndRaise(MinimumProperty, ref _minimum, value); @@ -102,7 +105,10 @@ namespace Avalonia.Controls.Primitives set { - ValidateDouble(value, "Maximum"); + if (!ValidateDouble(value)) + { + value = _maximum; + } if (IsInitialized) { @@ -129,7 +135,10 @@ namespace Avalonia.Controls.Primitives set { - ValidateDouble(value, "Value"); + if (!ValidateDouble(value)) + { + value = default; + } if (IsInitialized) { @@ -167,13 +176,9 @@ namespace Avalonia.Controls.Primitives /// Throws an exception if the double value is NaN or Inf. /// /// The value. - /// The name of the property being set. - private static void ValidateDouble(double value, string property) + private static bool ValidateDouble(double value) { - if (double.IsInfinity(value) || double.IsNaN(value)) - { - throw new ArgumentException($"{value} is not a valid value for {property}."); - } + return (!double.IsInfinity(value) || !double.IsNaN(value)); } /// From 73e1224ac33de0e100bbbd3be8333569b4553777 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Mon, 25 Nov 2019 21:55:26 +0800 Subject: [PATCH 2/4] Ignore changes if isnt a valid double value. --- src/Avalonia.Controls/Primitives/RangeBase.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Avalonia.Controls/Primitives/RangeBase.cs b/src/Avalonia.Controls/Primitives/RangeBase.cs index 39d00b6953..7155cceb8b 100644 --- a/src/Avalonia.Controls/Primitives/RangeBase.cs +++ b/src/Avalonia.Controls/Primitives/RangeBase.cs @@ -77,9 +77,9 @@ namespace Avalonia.Controls.Primitives { if (!ValidateDouble(value)) { - value = _minimum; + return; } - + if (IsInitialized) { SetAndRaise(MinimumProperty, ref _minimum, value); @@ -107,7 +107,7 @@ namespace Avalonia.Controls.Primitives { if (!ValidateDouble(value)) { - value = _maximum; + return; } if (IsInitialized) @@ -137,7 +137,7 @@ namespace Avalonia.Controls.Primitives { if (!ValidateDouble(value)) { - value = default; + return; } if (IsInitialized) @@ -178,7 +178,7 @@ namespace Avalonia.Controls.Primitives /// The value. private static bool ValidateDouble(double value) { - return (!double.IsInfinity(value) || !double.IsNaN(value)); + return !double.IsInfinity(value) || !double.IsNaN(value); } /// From f569287998ee37b90f5604683c11dd5704765e0e Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Mon, 25 Nov 2019 21:56:19 +0800 Subject: [PATCH 3/4] Update xml comment. --- src/Avalonia.Controls/Primitives/RangeBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Primitives/RangeBase.cs b/src/Avalonia.Controls/Primitives/RangeBase.cs index 7155cceb8b..baa51f92ec 100644 --- a/src/Avalonia.Controls/Primitives/RangeBase.cs +++ b/src/Avalonia.Controls/Primitives/RangeBase.cs @@ -173,7 +173,7 @@ namespace Avalonia.Controls.Primitives } /// - /// Throws an exception if the double value is NaN or Inf. + /// Checks if the double value is not inifinity nor NaN. /// /// The value. private static bool ValidateDouble(double value) From e23da2873111e7fabdf12c2e56abddca6d180aa0 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Mon, 25 Nov 2019 23:13:01 +0800 Subject: [PATCH 4/4] Remove obsolete unit test. --- .../Primitives/RangeBaseTests.cs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/tests/Avalonia.Controls.UnitTests/Primitives/RangeBaseTests.cs b/tests/Avalonia.Controls.UnitTests/Primitives/RangeBaseTests.cs index e2eb628512..34e6b228d0 100644 --- a/tests/Avalonia.Controls.UnitTests/Primitives/RangeBaseTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Primitives/RangeBaseTests.cs @@ -82,22 +82,6 @@ namespace Avalonia.Controls.UnitTests.Primitives Assert.Equal(50, target.Value); } - [Fact] - public void Properties_Should_Not_Accept_Nan_And_Inifinity() - { - var target = new TestRange(); - - Assert.Throws(() => target.Minimum = double.NaN); - Assert.Throws(() => target.Minimum = double.PositiveInfinity); - Assert.Throws(() => target.Minimum = double.NegativeInfinity); - Assert.Throws(() => target.Maximum = double.NaN); - Assert.Throws(() => target.Maximum = double.PositiveInfinity); - Assert.Throws(() => target.Maximum = double.NegativeInfinity); - Assert.Throws(() => target.Value = double.NaN); - Assert.Throws(() => target.Value = double.PositiveInfinity); - Assert.Throws(() => target.Value = double.NegativeInfinity); - } - [Theory] [InlineData(true)] [InlineData(false)]