【发布时间】:2009-07-28 08:44:30
【问题描述】:
我有一个带有性别的组合框(男,女..):我要求用户选择一个值(默认情况下,组合框没有值。)
<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;
}
}
}
问题是它从不输入 this[string columnname]。
当我尝试使用名称的 TextBox 时,它会输入 this[string columnname] 并且一切正常:
<TextBox Style="{StaticResource textBoxInError}" Text="{Binding Path=Surname, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}"/>
【问题讨论】:
标签: wpf validation combobox