forked from jeremybytes/SlideShow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValueRangeRule.cs
More file actions
38 lines (32 loc) · 1.01 KB
/
ValueRangeRule.cs
File metadata and controls
38 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.Globalization;
using System.Windows.Controls;
namespace SlideShow;
public class ValueRangeRule : ValidationRule
{
public double Min { get; set; }
public double Max { get; set; }
public ValueRangeRule()
{
}
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
if (value is string text)
{
var style = NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign;
if (!double.TryParse(text, style, CultureInfo.CurrentCulture, out double num))
{
return new ValidationResult(false, "Illegal characters");
}
if ((num < Min) || (num > Max) || string.IsNullOrEmpty(text))
{
return new ValidationResult(false,
$"Valid range: {Min} to {Max}");
}
}
else
{
return new ValidationResult(false, "Invalid input type");
}
return ValidationResult.ValidResult;
}
}