我有一个包含性别选项(男,女...)的ComboBox:要求用户选择一个值(ComboBox默认没有值)。
问题在于它从未进入此[string columnname]。当我尝试使用名称为TextBox的文本框时,它会进入此[string columnname],一切正常工作。
<ComboBox ItemsSource="{x:Static Member=data:Sex.AllTypes}" SelectedItem="{Binding Path=Sex.Value, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}" VerticalAlignment="Top">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Sex.Value是我Person类中的一个属性:
public class Person : IDataErrorInfo
{
public string this[string columnName]
{
get
{
switch (columnName)
{
case "Sex": return Sex.Value == null ? "Required field" : null;
case "Surname": return string.IsNullOrEmpty(Nachname) ? "Required field" : null;
}
}
}
public string Error
{
get
{
return null;
}
}
}
问题在于它从未进入此[string columnname]。当我尝试使用名称为TextBox的文本框时,它会进入此[string columnname],一切正常工作。
<TextBox Style="{StaticResource textBoxInError}" Text="{Binding Path=Surname, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}"/>