Created converters to show valid and invalid inputs.

This commit is contained in:
2025-05-27 08:44:24 -04:00
parent cfe9156ea4
commit f9e6c8c785
2 changed files with 74 additions and 0 deletions

View File

@@ -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();
}
}
}

View File

@@ -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();
}
}
}