I have a ComboBox with Sex (male, female ..): And I require the user to select a value (by default, the ComboBox does not matter.)
<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 is a property of the my Person class:
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; } } }
the problem is that it never goes into this [string columnname].
When I try to use a TextBox with a name, it enters this [string columnname] and everything works fine:
<TextBox Style="{StaticResource textBoxInError}" Text="{Binding Path=Surname, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}"/>
source share