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

标签 c# .net silverlight

我目前正在开发 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/

相关文章:

c# - 我能否始终确定通过 FindWindowEx 找到的控件的层次顺序?

c# - 在哪里可以找到免费的 C# 电子书?

.net - 对于 Windows 窗体,PostMessage 与 self 的等价物是什么?

c# - EF 4.0 实体属性 setter 抛出 ArgumentOutRangeException

silverlight - 有没有办法从 ViewModel 中调用 Navigate?

silverlight - IE9 Rendering Left-To-Right 标记

c# - 使只读属性在派生类中可写

c# - 如何在单击文本框时清除它?

c# - ASP.NET MVC : How many repositories?

.net - 如何在 Silverlight 数据网格中删除鼠标悬停突出显示和选定行突出显示