我有一个清单视图,其中一个列包含一个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的绑定路径,但我只是在讨论这个问题。
谢谢!
发布于 2014-07-09 18:22:25
问题是您已经为SelectedItem和SelectedValue绑定了comboBox。此外,它们被绑定在同一财产上。
摆脱了SelectedItem绑定,它就可以正常工作了。(SelectedItem比SelectedValue有更高的偏好)
<GridViewColumn Header="Database Type">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox Width="140"
ItemsSource="{Binding Source={StaticResource
DatabaseTypeFromEnum}}">
<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>https://stackoverflow.com/questions/24656769
复制相似问题