using System.Globalization; using System.Windows.Controls; namespace Sai.Toolkit.Mvvm.ValidationRules { public class UndefinedCharRules : ValidationRule { public override ValidationResult Validate(object value, CultureInfo cultureInfo) { char[] chars = new[] { '\\', ':', '{', '}', '[', ']', '|', ';', '<', '>', '?', '`', '~' }; if (value != null) { foreach (var c in chars) { if (value.ToString().IndexOf(c) > -1) { return new(false, $"名称不能包含字符:'\\ : [ ] | {{}}; < > ? ` ~"); } } } return ValidationResult.ValidResult; } } }