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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Globalization;
namespace FLY.ControlLibrary.Rules
{
public class FileNameRule : ValidationRule
{
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
if (value == null)
return new ValidationResult(false, "不能为空值!");
if (!(value is string))
return new ValidationResult(false, "不能为空字符串!");
string filename = value as string;
if (string.IsNullOrEmpty(filename))
return new ValidationResult(false, "不能为空字符串!");
foreach (char rInvalidChar in System.IO.Path.GetInvalidFileNameChars())
if (filename.Contains(rInvalidChar))
{
string msg = "不能包含";
foreach (char c in System.IO.Path.GetInvalidFileNameChars())
msg += c;
return new ValidationResult(false, msg);
}
return new ValidationResult(true, null);
}
}
}