From d40554dd0d6ecee0358ad42730096dfecdbb9efd Mon Sep 17 00:00:00 2001 From: agas <08fedra@interia.pl> Date: Mon, 2 May 2022 16:09:40 +0200 Subject: [PATCH 1/2] dBConverter fixed. --- LiveSPICE/Utils/dBConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LiveSPICE/Utils/dBConverter.cs b/LiveSPICE/Utils/dBConverter.cs index c56978ca..fa974098 100644 --- a/LiveSPICE/Utils/dBConverter.cs +++ b/LiveSPICE/Utils/dBConverter.cs @@ -12,7 +12,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { - return Math.Pow(10, (double)value / 20); + return Math.Pow(10, System.Convert.ToDouble(value) / 20); } } } From 99a5590ce797b2d1e5da45c5b08f3cf7c9578a4b Mon Sep 17 00:00:00 2001 From: agas <08fedra@interia.pl> Date: Mon, 2 May 2022 18:06:37 +0200 Subject: [PATCH 2/2] validation --- LiveSPICE/LiveSimulation.xaml | 17 ++++++++++++++--- LiveSPICE/Utils/dBConverter.cs | 6 +++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/LiveSPICE/LiveSimulation.xaml b/LiveSPICE/LiveSimulation.xaml index 066334a0..641d9d6f 100644 --- a/LiveSPICE/LiveSimulation.xaml +++ b/LiveSPICE/LiveSimulation.xaml @@ -95,7 +95,7 @@ - + @@ -121,6 +121,17 @@ + + + @@ -128,7 +139,7 @@ Text="Gain: " TextAlignment="Right" VerticalAlignment="Center" /> @@ -160,7 +171,7 @@ - + diff --git a/LiveSPICE/Utils/dBConverter.cs b/LiveSPICE/Utils/dBConverter.cs index fa974098..5c76bd29 100644 --- a/LiveSPICE/Utils/dBConverter.cs +++ b/LiveSPICE/Utils/dBConverter.cs @@ -12,7 +12,11 @@ public object Convert(object value, Type targetType, object parameter, CultureIn } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { - return Math.Pow(10, System.Convert.ToDouble(value) / 20); + if (value is string s && double.TryParse(s, out var dbValue)) + { + return Math.Pow(10, dbValue / 20); + } + return value; } } }