正如标题所说,我正在尝试验证我的表单,但我在获取组合框值时遇到了问题:
<ComboBox Name="ComboBox_Country"
Validation.Error="Validation_Error"
Text="{Binding UpdateSourceTrigger=PropertyChanged,
Path=Form_Country,
ValidatesOnDataErrors=true,
NotifyOnValidationError=true}"/>
然后使用我的类 FormValidation 进行验证,如下所示:
public string this[string columnName]
{
get
{
string result = null;
if (columnName == "Form_Country")
{
if (string.IsNullOrEmpty(Form_Country) || !verifyNumericValue(Form_Country))
result = "Please choose a correct option.";
}
}
我使用这些函数在我的表单中调用验证。
private void Confirm_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = _errors == 0;
e.Handled = true;
}
private void Confirm_Executed(object sender, ExecutedRoutedEventArgs e)
{
_generic = new UnidadValidation();
grid_UnidadData.DataContext = _generic;
e.Handled = true;
}
private void Validation_Error(object sender, ValidationErrorEventArgs e)
{
if (e.Action == ValidationErrorEventAction.Added)
_errors++;
else
_errors--;
}
我希望获得选定的值,而不是选定的文本。我最好的选择是什么?