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
我已经尝试编写此验证代码,
<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>
对于 TextBox 和另一个像这样的组件 Validation Working as well only for ComboBox 我遇到了这个问题
这是我的验证,我知道这将 Return ValidationResult.ValidResult 成功
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!");
}
}
我解决了我的问题
将<ComboBox.Text>
替换为<ComboBox.SelectedValue>
5 小时后...但我希望这对其他人有帮助...
我已经尝试编写此验证代码,
<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>
对于 TextBox 和另一个像这样的组件 Validation Working as well only for ComboBox 我遇到了这个问题 这是我的验证,我知道这将 Return ValidationResult.ValidResult 成功
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!");
}
}
我解决了我的问题
将<ComboBox.Text>
替换为<ComboBox.SelectedValue>
5 小时后...但我希望这对其他人有帮助...