refactor: massive refactor input elements, step 1/3

This commit is contained in:
NaBian committed 2022-03-13 18:54:34 +08:00
1 parent 1154eabd8d
commit 99d2fafb72
35 files changed
+1213 -1460

No files matched your search

@@ -0,0 +1,24 @@
using System.Globalization;
using System.Windows.Controls;
namespace HandyControl.Tools;
public class NoBlankTextRule : ValidationRule
{
public string ErrorContent { get; set; } = Properties.Langs.Lang.IsNecessary;
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
if (value is not string text)
{
return new ValidationResult(false, Properties.Langs.Lang.FormatError);
}
if (string.IsNullOrEmpty(text))
{
return new ValidationResult(false, ErrorContent);
}
return ValidationResult.ValidResult;
}
}
@@ -0,0 +1,44 @@
using System.Globalization;
using System.Windows.Controls;
using HandyControl.Data;
namespace HandyControl.Tools;
public class RegexRule : ValidationRule
{
public TextType Type { get; set; }
public string Pattern { get; set; }
public string ErrorContent { get; set; } = Properties.Langs.Lang.FormatError;
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
if (value is not string text)
{
return CreateErrorValidationResult();
}
if (!string.IsNullOrEmpty(Pattern))
{
if (!text.IsKindOf(Pattern))
{
return CreateErrorValidationResult();
}
}
else if (Type != TextType.Common)
{
if (!text.IsKindOf(Type))
{
return CreateErrorValidationResult();
}
}
return ValidationResult.ValidResult;
}
private ValidationResult CreateErrorValidationResult()
{
return new ValidationResult(false, ErrorContent);
}
}