ValidationSummary不显示组合框验证错误

时间:2010-10-11 15:22:57

标签: validation silverlight-4.0

在silverlight 4中,我有组合框和其他控件。 ValidationSummary可以并且确实显示控制的验证错误,但组合框错误除外。 这是我的XAML

<ComboBox x:Name="cmbGender" Grid.Row="6" Grid.Column="1" Margin="5,5,0,0" Width="100"
        HorizontalAlignment="Left" VerticalAlignment="Center" 
        sdk:ValidationSummary.ShowErrorsInSummary="True"
        ItemTemplate="{StaticResource cmbGenderItemTemplate}"
        IsEnabled="{Binding IsAddingOrEditing}" 
        ItemsSource="{Binding Genders}" 
        SelectedItem="{Binding EmployeeDetails.Gender, Mode=TwoWay, 
        ValidatesOnDataErrors=True, ValidatesOnNotifyDataErrors=True, 
        ValidatesOnExceptions=True, NotifyOnValidationError=True}" 
        />

在我的VM中,我将此元数据绑定到SelectedItem

    [Display(Name = "LabelGender", ResourceType = typeof(AnnotationResources))]
    [Required(ErrorMessageResourceName = "ValidationGenderRequired",
              ErrorMessageResourceType = typeof(AnnotationResources))]
    public GenderData Gender
    {
        get
        {
            return _gender;
        }
        set
        {
            if (value != _gender)
            {
                _gender = value;
                this.RaisePropertyChanged("Gender");

                Validator.ValidateProperty(
                    _gender,
                    new ValidationContext(this, null, null) { MemberName = "Gender" });
            }
        }
    }

这是我的用于validationSummary的XAML

<sdk:ValidationSummary Margin="0,5,0,0" Target="{Binding ElementName=gridDetails}" />

但是如果我调用Validator.TryValidateObject,那些错误(组合框错误)就在那里。
请帮助,已经花了几天谷歌搜索这个问题没有运气。

1 个答案:

答案 0 :(得分:0)

我的问题是因为我检查了新的属性值,当我删除这一行时:

if (value != _gender)

一切正常