0
在ComboBoxNotEmptyValidationRule
類使用Int32.Parse
後後的錯誤,我得到一個錯誤:WPF - 使用Int32.Parse
Input string was not in a correct format.
當我添加到XAML:
<local:ComboBoxNotEmptyValidationRule x:Name="Number" ValidatesOnTargetUpdated="True"/>
計劃是normaly運行,這walidation工作正常。在設計窗口我沒有任何內容,只有FormatException: Input string was not in a correct format.
消息。當我在XAML中評論這一行時,一切都很好。
class ComboBoxNotEmptyValidationRule : ValidationRule
{
public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
{
int str = -1;
str = Int32.Parse(value as string);
if (str > 0)
{
if (str > 0)
return ValidationResult.ValidResult;
}
return new ValidationResult(false, "please fill required field");
}
}
你能顯示更多的代碼嗎?我們不知道「ComboBoxNotEmptyValidationRule」是什麼,等等。 – 2013-02-08 18:34:28
@ Jeff-Meadows我添加了這個類。 – user1031034 2013-02-08 18:46:49
你確定值是字符串類型嗎?價值的內容是什麼? – LPL 2013-02-08 19:02:18