c# – Silveright验证在修复验证错误后抛出异常

我目前正在开发Silverlight业务应用程序,并且第一次进入验证阶段.当我收到验证错误时,控件将按预期显示错误,但是当我修复验证错误并移动到DataForm中的下一个字段(实际上是Telerik RadDataForm,它的价值)时,我得到一个ArgumentOutOfRangeException抛出我的实体在.g.cs文件中的setter.这是生成的代码:

[DataMember()]
[Display(Name="Email / User Name")]
[RegularExpression("^.*@.*\\..*$", ErrorMessage="Must be a valid e-mail address")]
[Required()]
public string Email
{
    get
    {
        return this._email;
    }
    set
    {
        if ((this._email != value))
        {
            this.OnEmailChanging(value);
            this.RaiseDataMemberChanging("Email");
            this.ValidateProperty("Email", value); // <-- Exception thrown here
            this._email = value;
            this.RaiseDataMemberChanged("Email");
            this.OnEmailChanged();
        }
    }
}

这是导致验证的控件的Xaml:

<telerik:RadDataForm Grid.Row="0" Style="{StaticResource GridPageFormStyle}" 
                 x:Name="addForm" EditEnded="AddEnded" Header="Add">
    <telerik:RadDataForm.EditTemplate>
        <DataTemplate>
            <StackPanel>
                <telerik:DataFormDataField 
                                DataMemberBinding="{Binding Email, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" 
                                Label="E-mail Address" />
                <telerik:DataFormComboBoxField 
                                DataMemberBinding="{Binding Role, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" 
                                ItemsSource="{Binding Roles, ElementName=This}" Label="Role" />
                <telerik:DataFormComboBoxField DataMemberBinding="{Binding Partner, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" 
                                               ItemsSource="{Binding Partners, ElementName=This}" Label="Partner" />
            </StackPanel>
        </DataTemplate>
    </telerik:RadDataForm.EditTemplate>
    </telerik:RadDataForm>

这是例外的文本:

    {System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)}

有谁知道为什么抛出这个异常,或者有一个很好的调试策略?我无法进入实际抛出异常的代码.

最佳答案 我不确定究竟发生了什么,但事实证明我可以在调试时跳过错误并且一切正常.此外,在没有调试的情况下运行时甚至不会发生错误,所以我现在暂时忽略它.

点赞