就像标题所说的那样,我正在尝试验证我的表单,但是我在获取组合框值时遇到了问题:
<ComboBox Name="ComboBox_Country"
Validation.Error="Validation_Error"
Text="{Binding UpdateSourceTrigger=PropertyChanged,
Path=Form_Country,
ValidatesOnDataErrors=true,
NotifyOnValidationError=true}"/>
Run Code Online (Sandbox Code Playgroud)
然后使用我的类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.";
}
}
Run Code Online (Sandbox Code Playgroud)
我使用这些函数在我的表单中调用验证.
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--;
}
Run Code Online (Sandbox Code Playgroud)
我希望得到所选的值,而不是所选的文本.什么是我最好的选择?
对我来说,愚蠢,愚蠢的缺乏观察力.如果你要改变组合框的Text来SelectedValue,而不是像这样:
<ComboBox Name="ComboBox_Pais"
Validation.Error="Validation_Error"
SelectedValue="{Binding UpdateSourceTrigger=PropertyChanged,
Path=Escuela_Pais,
ValidatesOnDataErrors=true,
NotifyOnValidationError=true}"/>
Run Code Online (Sandbox Code Playgroud)
一个将获得所选值而不是文本.
对于那些可能想要阅读的人,我在这里找到了原始教程.
使用IDataErrorInfo进行WPF TextBox验证
| 归档时间: |
|
| 查看次数: |
13359 次 |
| 最近记录: |