开发者

ValidationSummary doesn't show combobox validation error

开发者 https://www.devze.com 2023-01-19 07:42 出处:网络
In silverlight 4, I have combobox and other controls. ValidationSummary can and does shows control\'s validation errors, except comboboxes errors.

In silverlight 4, I have combobox and other controls. ValidationSummary can and does shows control's validation errors, except comboboxes errors. Here is my 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}" 开发者_JAVA百科
        SelectedItem="{Binding EmployeeDetails.Gender, Mode=TwoWay, 
        ValidatesOnDataErrors=True, ValidatesOnNotifyDataErrors=True, 
        ValidatesOnExceptions=True, NotifyOnValidationError=True}" 
        />

And in my VM I have this Metadata bind to 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" });
            }
        }
    }

And this is my XAML for validationSummary

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

But if I call Validator.TryValidateObject, those errors (comboBoxes errors) are there.

Please help, already spent days googling for this issue with no luck.


My problem was because I check the new property value, and when I delete this line:

if (value != _gender)

Everything works fine

0

精彩评论

暂无评论...
验证码 换一张
取 消