29 lines
821 B
C#
29 lines
821 B
C#
using System;
|
|
using System.Globalization;
|
|
using System.Windows.Controls;
|
|
|
|
namespace ENI2.Util
|
|
{
|
|
public class RequiredDateValidationRule : ValidationRule
|
|
{
|
|
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
|
|
{
|
|
if (value == null)
|
|
return new ValidationResult(false, "Date is required");
|
|
|
|
if (value is DateTime dt)
|
|
{
|
|
if (dt == default(DateTime))
|
|
return new ValidationResult(false, "Date is required");
|
|
}
|
|
else if (value is string text)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(text))
|
|
return new ValidationResult(false, "Date is required");
|
|
}
|
|
|
|
return ValidationResult.ValidResult;
|
|
}
|
|
}
|
|
}
|