我目前正在开发 Silverlight 商业应用程序,这是我第一次进入验证阶段。当我收到验证错误时,控件将按预期显示错误,但是当我修复验证错误并移至 DataForm 中的下一个字段(实际上是 Telerik RadDataForm,就其值(value)而言)时,我收到 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)}
有谁知道为什么抛出这个异常,或者有调试它的好策略?我无法进入实际抛出异常的代码。
最佳答案
我不确定到底发生了什么,但事实证明我可以在调试时跳过错误并且一切正常。此外,在没有调试的情况下运行时甚至不会出现错误,所以我暂时忽略它。
关于c# - Silveright 验证在修复验证错误后抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6351099/