From f9e6c8c785d0712479686f21b2d7bb44df44378c Mon Sep 17 00:00:00 2001 From: Kalakoi Date: Tue, 27 May 2025 08:44:24 -0400 Subject: [PATCH] Created converters to show valid and invalid inputs. --- .../DoubleTextBackgroundConverter.cs | 37 +++++++++++++++++++ .../Converters/IntTextBackgroundConverter.cs | 37 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 osrs-toolbox/Converters/DoubleTextBackgroundConverter.cs create mode 100644 osrs-toolbox/Converters/IntTextBackgroundConverter.cs diff --git a/osrs-toolbox/Converters/DoubleTextBackgroundConverter.cs b/osrs-toolbox/Converters/DoubleTextBackgroundConverter.cs new file mode 100644 index 0000000..e1add66 --- /dev/null +++ b/osrs-toolbox/Converters/DoubleTextBackgroundConverter.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using System.Windows.Media; + +namespace osrs_toolbox +{ + public class DoubleTextBackgroundConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + string Value = value as string; + if (string.IsNullOrEmpty(Value)) return new SolidColorBrush(Colors.Aquamarine); + else + { + try + { + System.Convert.ToDouble(Value); + return new SolidColorBrush(Colors.White); + } + catch + { + return new SolidColorBrush(Colors.Red); + } + } + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/osrs-toolbox/Converters/IntTextBackgroundConverter.cs b/osrs-toolbox/Converters/IntTextBackgroundConverter.cs new file mode 100644 index 0000000..3a39be5 --- /dev/null +++ b/osrs-toolbox/Converters/IntTextBackgroundConverter.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using System.Windows.Media; + +namespace osrs_toolbox +{ + public class IntTextBackgroundConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + string Value = value as string; + if (string.IsNullOrEmpty(Value)) return new SolidColorBrush(Colors.Aquamarine); + else + { + try + { + System.Convert.ToInt32(Value); + return new SolidColorBrush(Colors.White); + } + catch + { + return new SolidColorBrush(Colors.Red); + } + } + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +}