我有一个 Listview,其中一列包含 TextBox,另一列包含 ComboBox。
此验证适用于 TextBox:
<GridViewColumn Header="SQL Server">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Width="140">
<TextBox.Text>
<Binding Path="Server" Mode="TwoWay" NotifyOnValidationError="True"
ValidatesOnExceptions="True" ValidatesOnDataErrors="True"
UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<helpers:DatabaseServerNameValidationRule />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
但是当我用 ComboBox 尝试相同的方法时,我的验证器永远不会被调用:
<GridViewColumn Header="Database Type">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox Width="140" ItemsSource="{Binding Source={StaticResource DatabaseTypeFromEnum}}" SelectedItem="{Binding DatabaseType, Mode=TwoWay}">
<ComboBox.SelectedValue>
<Binding Path="DatabaseType"
NotifyOnValidationError="True"
ValidatesOnExceptions="True"
ValidatesOnDataErrors="True"
UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<helpers:DatabaseTypeValidationRule />
</Binding.ValidationRules>
</Binding>
</ComboBox.SelectedValue>
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
我也试过用<ComboBox.SelectedValue>
没有<ComboBox.SelectedValuePath>
效果替换。
我的问题可能在于 ComboBox 的绑定路径,但此时我只是在挣扎。
谢谢!