【发布时间】:2011-11-25 18:20:42
【问题描述】:
我目前正在开发 Silverlight 商业应用程序,并且是第一次进行验证。当我收到验证错误时,控件将按预期显示错误,但是当我修复验证错误并移至 DataForm 中的下一个字段(实际上是 Telerik RadDataForm,值得一提)时,我得到了 ArgumentOutOfRangeException在 .g.cs 文件中我的实体设置器中抛出。这是生成的代码:
[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# .net silverlight