summaryrefslogtreecommitdiff
path: root/Gestor.Common/Gestor.Common.Converters/ZeroToEmptyConverter.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Gestor.Common/Gestor.Common.Converters/ZeroToEmptyConverter.cs')
-rw-r--r--Gestor.Common/Gestor.Common.Converters/ZeroToEmptyConverter.cs36
1 files changed, 36 insertions, 0 deletions
diff --git a/Gestor.Common/Gestor.Common.Converters/ZeroToEmptyConverter.cs b/Gestor.Common/Gestor.Common.Converters/ZeroToEmptyConverter.cs
new file mode 100644
index 0000000..7d3be65
--- /dev/null
+++ b/Gestor.Common/Gestor.Common.Converters/ZeroToEmptyConverter.cs
@@ -0,0 +1,36 @@
+using System;
+using System.Globalization;
+using System.Windows.Data;
+using System.Windows.Markup;
+
+namespace Gestor.Common.Converters;
+
+public class ZeroToEmptyConverter : MarkupExtension, IValueConverter
+{
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value != null)
+ {
+ if (value is string)
+ {
+ return value;
+ }
+ if (!(Math.Abs(System.Convert.ToDouble(value)) < 0.01))
+ {
+ return value.ToString();
+ }
+ return "";
+ }
+ return "";
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return (value != null && !string.IsNullOrEmpty(value.ToString())) ? int.Parse(value.ToString()) : 0;
+ }
+
+ public override object ProvideValue(IServiceProvider serviceProvider)
+ {
+ return this;
+ }
+}