Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Silverlight验证_C#_.net_Silverlight - Fatal编程技术网

C# Silverlight验证

C# Silverlight验证,c#,.net,silverlight,C#,.net,Silverlight,我有这样一个验证规则: public class MyRule : ValidationRule { public override ValidationResult Validate(object value, CultureInfo cultureInfo) { if ((int)value < 0) { return new ValidationResult("Error, value must be >

我有这样一个验证规则:

public class MyRule : ValidationRule
{

    public override ValidationResult Validate(object value, CultureInfo cultureInfo)
    {
        if ((int)value < 0)
        {
            return new ValidationResult("Error, value must be > 0");
        }
        else
        {
            return ValidationResult.Success;
        }
    }
}
公共类MyRule:ValidationRule
{
公共覆盖验证结果验证(对象值,CultureInfo CultureInfo)
{
如果((int)值小于0)
{
返回新的ValidationResult(“错误,值必须大于0”);
}
其他的
{
返回ValidationResult.Success;
}
}
}
如何将其应用于DataGrid中的列,以便在绑定DataGrid时触发它,而不仅仅是在用户更改单元格时。 我的专栏

            <data:DataGridTextColumn Header="BookSize" Binding="{Binding BookSize.Value}" >

            </data:DataGridTextColumn>

在包含BookSize属性的元数据类中,添加以下属性:

[CustomValidation(typeof(MyRule), "MyRuleValidation",
                  ErrorMessage = "Your Error Message")]
public int BookSize;
我猜是int,但它应该会让你知道应该把它放在哪里