33 lines
980 B
C#
33 lines
980 B
C#
// Copyright (c) 2017- schick Informatik
|
|
// Description: Validation for direct in-grid editing
|
|
//
|
|
|
|
using System;
|
|
using System.Globalization;
|
|
using System.Windows.Controls;
|
|
|
|
namespace ENI2.Util
|
|
{
|
|
public class NumberValidationRule : ValidationRule
|
|
{
|
|
public double? MaxValue { get; set; }
|
|
|
|
public double MinValue { get; set; } = 0;
|
|
|
|
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
|
|
{
|
|
if (!double.TryParse(Convert.ToString(value), out double aDouble))
|
|
return new ValidationResult(false, "Illegal characters");
|
|
|
|
if (((MaxValue != null) && (aDouble > MaxValue)) || (aDouble < MinValue))
|
|
{
|
|
return new ValidationResult(false, string.Format("Please enter a number in the range: {0} - {1}", MinValue, MaxValue));
|
|
}
|
|
else
|
|
{
|
|
return new ValidationResult(true, null);
|
|
}
|
|
}
|
|
}
|
|
}
|