Home > Mobile >  Validation Error : value "" could not be Converted xml in WPF ComboBox when Selected Item
Validation Error : value "" could not be Converted xml in WPF ComboBox when Selected Item

Time:09-24

I have tried to code this validation, enter image description here

 <ComboBox Name="CmbPlace" DisplayMemberPath="Name" 
                              SelectedValuePath="PlaceId" 
                              materialDesign:ComboBoxAssist.ShowSelectedItem="true"
                              Width="130" HorizontalContentAlignment="Right" Margin="5"
                              DropDownOpened="CmbPlace_OnDropDownOpened">
                        <ComboBox.Text>
                            <Binding Path="PlaceId">
                                <Binding.ValidationRules>
                                    <validation:RequireCmbValidation ValidatesOnTargetUpdated="True"/>
                                </Binding.ValidationRules>
                            </Binding>
                        </ComboBox.Text>

for TextBox and another component like this Validation Working as well only for ComboBox I got this Problem this is my Validation and I know this will be Return ValidationResult.ValidResult successfully

public class RequireCmbValidation: ValidationRule
{
    public override ValidationResult Validate(object value, CultureInfo cultureInfo)
    {
        if (!string.IsNullOrWhiteSpace(value?.ToString()))
            if (value.ToString() != "0")
                return ValidationResult.ValidResult;
            else
                return new ValidationResult(false, "Please Select one Item");
        return new ValidationResult(false, "Required!");
    }
}

CodePudding user response:

I solved my problem

Replace <ComboBox.Text> to <ComboBox.SelectedValue>

after 5 hours... but I hope this will help others...

  • Related