Wpf: IDataErrorInfo not working with CollectionViewSource?
I have a ListBox bound to a CollectionView which again is bound to a property on a viewmodel.
<ListBox 开发者_StackOverflow中文版ItemsSource="{Binding Source={StaticResource pumpCurvesViewSource}, ValidatesOnDataErrors=true}" />
Now, the viewmodel implements IDataErrorInfo, but the validation of the property on the viewmodel is never triggered. If I skip the CollectionViewSource and bind directly to the property on the viewmodel, everything works as expected (meaning the view outputs a big red box around the ListBox when its invalid):
<ListBox ItemsSource="{Binding Path=PumpCurves, ValidatesOnDataErrors=true}" />
Now, how can I get the same behaviour when using a CollectionViewSource?
If the view model implements IDataErrorInfo, that means that it specifies which properties have validation errors. The properties the ViewModel is aware of, however, are the properties of the ViewModel, not any properties bound to properties bound to the view model. Try putting a CollectionView directly on the ViewModel, and binding to that instead.
精彩评论